Hello,
I’m not sure if this is a Bug, or if there are other reasons for this problem but assinging an int[] (Script2) to equal another int[] (Script 1) is causing both variables to be connected, so by changing the value of second int[](Script 2) is automatically updating the first int[] (Script 1) . By doing exactly the same with two normal int the behaviour is a completly different one. By Updating the int of Script 2, the int of Script 1 is staying unchanged.
So how can the behaviour of the same action end up being so different?
Script 1
using UnityEngine;
using System.Collections;
public class Script1 : MonoBehaviour {
public static Script1 Script1Singleton;
public int TestInteger =0;
public int[] TestIntegerArray ={0};
// Use this for initialization
void Awake () {
Script1Singleton =this;
}
}
Script 2
using UnityEngine;
using System.Collections;
public class Script2 : MonoBehaviour {
public int TestInteger =0;
public int[] TestIntegerArray ={0};
// Use this for initialization
void Start () {
TestInteger = Script1.Script1Singleton.TestInteger;
TestIntegerArray = Script1.Script1Singleton.TestIntegerArray;
}
// Update is called once per frame
void Update () {
TestInteger++;
TestIntegerArray[0]++;
print("Script1 Int: "+Script1.Script1Singleton.TestInteger+ " Script2 Int:"+TestInteger);
print("Script1 Int[]: "+Script1.Script1Singleton.TestIntegerArray[0]+ " Script2 Int[]:"+TestIntegerArray[0]);
}
}
Console Log