- Home /
Console Error
Please help this is the error I got well playing my game.
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, 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) Turret Control.Shoot () (at Assets/_Scripts/Turret Control.js:24) Turret Control.Update () (at Assets/_Scripts/Turret Control.js:15)
My Script is supposed to have a turret look at my character, and shoot one fireball a second, but it is spraying like crazy! Here is my code
var LookAtTarget : GameObject; var damp = 6.0; var bulletPrefab : 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);
}
}
} function Shoot(seconds) { if(seconds!=savedTime) { var bullet = Instantiate(bulletPrefab, transform.Find("SpawnPoint1").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 1000);
savedTime=seconds;
}
Answer by iwaldrop · Feb 14, 2013 at 01:08 AM
All you have to do is track when the last time you fired a shot was, and the shoot again if it's been at least as long as your interval.
var lastShootTime = 0;
var shootInterval = 2;
//shoot code
if (lastShootTime + shootInterval >= Time.time)
{
// shoot a fireball
lastShootime = Time.time;
}
Your answer
Follow this Question
Related Questions
Why do I get this error 0 Answers
My C# script brings back no results in the console 1 Answer
Why isn't my java code working? 2 Answers
What's the matter with my Cube.fbx? 0 Answers
SCRIPT NOT WORKING 2 Answers