- Home /
Question by
Cewein · Feb 26, 2018 at 05:06 PM ·
gameobjecttransform.positionthis
Cannot get the position of this script GameObject
I got a problem, when i'm referencing the gameObject :
Wolf is a class where pos is a Public vector3
Here the code:
public class Hunter : MonoBehaviour {
Wolf wolf;
SpawnSheep meat;
public GameObject hunter;
// Use this for initialization
void Start () {
meat = FindObjectOfType<SpawnSheep>();
wolf.pos = this.transform.position;
}
// Update is called once per frame
void Update () {
wolf.pos = this.transform.position;
for (int x = 0; x < meat.sheeps.Length; x++)
{
Debug.DrawLine(wolf.pos, meat.sheeps[x].pos, Color.red);
}
}
}
Comment
Best Answer
Answer by JedBeryll · Feb 26, 2018 at 05:21 PM
If this is all of the script then wolf is never assigned. Make it public and drag and drop in the inspector or find it the same way you do for the meat variable.
Answer by Tasarran · Feb 26, 2018 at 06:06 PM
You have defined what a Wolf is, but you never assign an instance of a Wolf to your variable "wolf".
You need to create a Wolf in your scene somehow, and make the "wolf" variable point to it.