- Home /
Slingshot script. Need help troubleshooting.
Hi guys.
This is my first real attempt at making a working script so bear with me pls.
I am making a slingshot mechanic. But it is giving me a null reference at the shootVector line. Any help in debuging would be appreciated.
var ammo : GameObject;
var multiplier : int;
var draggedPosition ;
var spawnPosition ;
rigidbody.Sleep();
function OnMouseUp ()
{
spawnPosition = GameObject.Find("Sphere").Transform;
draggedPosition = GameObject.Find("ammobull").Transform;
var shootVector = spawnPosition - draggedPosition;
ammo.rigidbody.AddForce(shootVector * multiplier, ForceMode.Impulse);
}
function Update () {
}
Comment
Answer by DaveA · Aug 22, 2012 at 10:59 PM
use 'transform' not 'Transform'
or it didn't find Sphere or ammobull, are you sure you assigned them both in the Inspector?
also you would want transform.position.
spawnPosition = GameObject.Find("Sphere").transform.position;
draggedPosition = GameObject.Find("ammobull").transform.position;
Better, you should pre-assign these if you are always using the same ones:
var sphere : Transform; // assign by drag/drop in Inspector (the Sphere object)
var ammo : Transform; // assign by drag/drop in Inspector (the ammobull object)
then you can use
spawnPosition = sphere.position; // for example
Your answer
Follow this Question
Related Questions
Weird angles with slingshot script. 1 Answer
Slingshot Based Game 1 Answer
wave spawn problems 1 Answer
Unchecking a prefab's script in the Inspector doesn't "deactivate" it? 1 Answer
third person double jump 0 Answers