Have an error.

I have a simple two codes to move object to spots. But i have two null errors,at start of the game : NullReferenceException at : follower = GameObject.Find (“Follower”).GetComponent< Follower >(); and second when im clicking at the object with a script Leaders :NullReferenceException: Object reference not set to an instance of an object at : follower.v3Dest = transform.position; Thank for any help!

public class Follower : MonoBehaviour
{

public Vector3 v3Dest;
public float speed = 5.0f;

void Start () {
v3Dest = transform.position;
}

void Update () {
transform.position = Vector3.MoveTowards(transform.position,v3Dest,Time.deltaTime * speed);
transform.LookAt(v3Dest);
}
}
And this script goes on any objects (i.e. the things you click on to change the destination):

public class Leaders : MonoBehaviour {

private Follower follower;

void Start () {
follower = GameObject.Find (“Follower”).GetComponent< Follower >();
}

void OnMouseDown() {
follower.v3Dest = transform.position;
}
}

First of all, use the advance thread feature to make your code a code formatted text :slight_smile: Anyway, a null exception does always say, that your script is trying to access something it can’t find. As I can see, you are assigning a component to your “follower” Var and than trying to move this Object. But , of course, you can’t transform a component :wink: You need to get rid of the "GetComponent(); because you just want the GameObject to be moved.

Like it’s written here: Unity - Scripting API: GameObject.Find

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    private GameObject hand;
    void Start() {
        hand = GameObject.Find("/Monster/Arm/Hand");
    }
    void Update() {
        hand.transform.Rotate(0, 100 * Time.deltaTime, 0);
    }
}

Oh my god :smile: I forgot to name my object :smile: