- Home /
Question by
Nicolla · Feb 01, 2012 at 03:33 AM ·
rigidbodyinstantiatenullreferenceexception
nullrefernceexception
i am getting a error when i use the following code when i try to add a velocity to the object and i am not sure why i am getting it as i am using the same code in a different script and not getting any errors
public Rigidbody Rocks;
private float NextShoot;
private Rigidbody CloneRocks;
void Start () {
NextShoot = Time.time +1;
}
void Update () {
if(Time.time > NextShoot)
{
NextShoot = Time.time + 10.0f;
CloneRocks = Instantiate(Rocks,transform.position ,transform.rotation) as Rigidbody;
this.CloneRocks.rigidbody.velocity = transform.TransformDirection (Vector3.forward * 10);
}
}
Comment
Well, you shouldn't need the 'this.' and the '.rigidbody.' bits in the line where you actually add the velocity. This line of code should do the same thing, more efficiently:
CloneRocks.velocity = yadda yadda yadda;
In any case, try making CloneRocks a gameObject, ins$$anonymous$$d.
thank for the help syclamoth making it a gameobject fix it thanks
and yeah i know the "this" and Rigidbody are not need was just trying thing out to see if it would fix my problem
Your answer
Follow this Question
Related Questions
AddForce NullReferenceException 1 Answer
Null variable 2 Answers