so i know nothing about java. i have just been following this intro tutorial for unity: link. there is a part where you have to make a script for a turret to shoot at you character. here's mine:
var LookAtTarget: Transform;
var damp = 6.0; var bullitPrefab: Transform; var savedTime=0;
function Update () { if(LookAtTarget) { var Rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, Rotate, Time.deltaTime * damp);
var seconds : int = Time.time;
var oddeven = (seconds % 2);
if(oddeven)
{
Shoot(seconds);
}
}
//transform.LookAt(LookAtTarget);
}
function Shoot(seconds) {
if(seconds)
{
var bullit = Instantiate(bullitPrefab, transform.Find("Turret Spawn").transform.position,
Quaternion.identity);
bullit.rigidbdy.AddForce(transform.forward * 2000);
savedTime=seconds;
}
}
then, i get this error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
if you saw the tutorial, the problem this creates is that the turret still just shoots out a spray every 1 second, rather than a single fireball every few seconds. thanks!