Lets say i have a class A which is instantiated as an object in a GameObject’s monobehaviour. The class A is supposed to have a direct control over the position of the GameObject (the monobehaviour’s gameObject.transform.position member).
I tried to do something like this in the monobehaviour.
using UnityEngine;
using System.Collections;
using Mynamespace; //contains the class A
public class MyMonobehaviour : MonoBehaviour {
public Vector3 myReference;
public A sampleObject;
void Start () {
myReference = gameObject.transform.position;
sampleObject = new A(ref myReference);
}
}
the class A is something like this:
public class A {
public Vector3 directReference;
public A (ref Vector3 temp) {
directReference = temp;
}
public void Access() {
Debug.Log("Current X position: " + directReference .x);
}
}
the question is, why it doesnt provide direct access to the GameObject’s position? if i try something like sampleObject.Access(); it wont display the current position of the gameobject, only the position it had at the moment of the A object instantiation.
Sorry for the long question but all of this driving me crazy, im a beginner, thanks.