I am trying to figure out how to instantiate a game object, save it off as a variable, and then access that variable so I can reposition it by accessing the transform. The first two steps I did seem to work fine, but the third step of trying to access the variable gives me a null reference exception.
I am not understanding something about saving off game objects or am I just missing some syntax?
Thanks in advance for any help!
========================================================
using UnityEngine;
using System.Collections;
public class TinkerTest : MonoBehaviour {
Transform newClone;
public Transform testObject;
// Use this for initialization
void Start () {
Transform newClone = Instantiate(testObject, new Vector3(5, 0, 0), Quaternion.identity) as Transform;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(“1”)) {
newClone.transform.position = new Vector3(0,0,0);
}
}
}