Hi! I have a problem with assigning a newly created instance’s script’s variables.
Here’s what i’m trying to do:
The player collides with trigger object. The trigger object is removed and the function addPiece is called like so:
function OnTriggerEnter (other:Collider) {
Destroy(other.gameObject);
addPiece();
}
This is what my addPiece looks like
function addPiece () {
var newPiece : GameObject = Instantiate(part, transform.position+Vector3(0, 1, 0), Quaternion.identity);
newPiece.name = "Piece";
newPiece.GetComponent.<SmoothFollow>().target = lastPiece.transform;
lastPiece = newPiece;}
part is prefab with a sphere that has SmoothFollow attached to it. I’m trying to set the target variable of SmoothFollow attached to the created newPiece to lastPiece’s (a GameObject) transform. I’ve been googling like crazy, seatching this forum and reading the scripting reference and various tutorials to no luck. The instantiation works (i see sphere falling from the sky), but it does not set a target to follow. Instead, i get:
NullReferenceException
Mato.addPiece () (at Assets/Scripts/Mato.js:34)
Mato.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Mato.js:27)
So how do I make this work?