I just learned that in a C# tutorial, that we can declare var name = new ClassNameOfOtherScript();var name = new ClassNameOfOtherScript(); to create a new class object, then use the object to call the function in that class, but it don'tdoesn't seem to be working in unityUnity.
Am I understandunderstanding it wronglywrong or in unity itsdoes it work differently in Unity?
I have a class Cube1,Cube1 this is attached to an object with spriterendererSpriteRenderer enabled. Then I have another script(clock controller) ClockController which is not attach to any object. When I run it, the color of cube does not change to red?
public class Cube1 : MonoBehaviour
{
public void Rectangle()
{
GetComponent<SpriteRenderer>().color = Color.red;
}
}
public class ClockController : MonoBehaviour
{
void Start()
{
var cube1 = new Cube1();
cube1.Rectangle();
}
public class Cube1 : MonoBehaviour
{
public void Rectangle()
{
GetComponent<SpriteRenderer>().color = Color.red;
}
}
}
public class ClockController : MonoBehaviour
{
void Start()
{
var cube1 = new Cube1();
cube1.Rectangle();
}
}