Rigidbody newBall = Instantiate(ball, position, transform.rotation) as Rigidbody;
newBall.transform.localScale = new Vector(.5f,.5f,.5f)
Returns and null reference error.
Rigidbody newBall = Instantiate(ball, position, transform.rotation) as Rigidbody;
newBall.transform.localScale = new Vector(.5f,.5f,.5f)
Returns and null reference error.
I would assume that your “ball” prefab is not of type Rigidbody, so trying to cast newBall to Rigidbody results in null.
Sorry, misunderstood the question, assumed heretic was trying to add a rigidbody component. Deleted my wrongfuly accepted answer.
– gregzoyeah, but your comment lead me to the right answer., not saying Eric5h5 was wrong, yours just got me there.
– heretic619Now its marked as answered but there's no answer! I'd edited my post to reflect the new information (point to Eric's post). Well that's my two cents :)
– by0log1c
Thank you I needed to cast it as a GameObject.
– heretic619I'd personnally avoid writing float without the integer number. It leads to confusion and won't compile in a declaration. var myFloat:float = .5f; won't work
– by0log1c@BY0LOG1C: Huh? "var myFloat:float = .5f;" is perfectly valid, although it's JS and not C#. In C#, "var myFloat = .5f;" or "float myFloat = .5f;" are fine.
– Eric5h5The answer to the problem should be: GameObject newBall = Instantiate(ball, position, transform.rotation) as GameObject; newBall.transform.localScale = new Vector(.5f,.5f,.5f)
– heretic619Totally my bad, must've tested it too quickly... You always pick up my errors, Eric! Sorry for the erroneous info but in any case, I'd still write floats as the full number 0.5f. Another two cents of mine.
– by0log1c