Hey everyone! i have a small error and i am hoping the title is right for my problem, but sorry if it isn’t.
I have a game in which the user can click on the floor and a node will appear on the floor where the mouse is, and if they click anywhere else the node will move to that location. This code works perfectly.
I also have another code in which uses the Nodes as way points in which my tank will follow when its clicked. I have the click code working, but i am trying to get the way point code to search the Game world for the Node in which i Instantiated with the click code. I can make it find it using Game Objects but the code requires it to be a transform variable. Please help me my way point code is,
var waypoint : Transform;
var speed : float = 20;
static var pointput = false;
function Update ()
{
if (Waypoints.pointput == true)
{
waypoint = transform.Find("Tank_Waypoint(Clone)");//i am guessing this is the problem?
if (Unit_Press.selectionhudon == true)
{
var target : Vector3 = waypoint.position;//This is the line with the error
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
velocity = Vector3.zero;
}
else
{
velocity = moveDirection.normalized * speed;
}
}
rigidbody.velocity = velocity;
transform.LookAt(target);
}
}
When run i click on my tank, and it puts the selection box around it, then when i right click on the floor it places the Node but shows an error when the tank try’s to follow it. The waypoint code does work when the nodes are already in the scene but i am trying to make it so i have to place the nodes. The error is,
NullReferenceException
UnityEngine.Transform.get_position () (at C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/Editor/UnityEngineTransform.cs:19)
Waypoints.Update () (at Assets/Scripts/Waypoints.js:12)
please help me! thank you very much to who ever does