Hi, I need some help with a C4 script. It’s not mine, its written by OcularCash of armedunity.com.
here is the throw script.
var C4Prefab : Transform;
var throwForce = 500;
//public var DrawAudio : AudioClip;
//public var ThrowAudio : AudioClip;
//public var C4TriggerAudio : AudioClip;
var isHolding = false;
var CanDetonate = false;
var DetonationSwitch = false;
function Update()
{
if(Input.GetKeyDown("t")(CanDetonate == false))
{
//audio.PlayOneShot(DrawAudio);
//animation.Play("C4Draw");
isHolding = true;
}
if(Input.GetKeyUp("t")(isHolding == true))
{
//audio.PlayOneShot(ThrowAudio);
var C4 = Instantiate(C4Prefab, transform.position, Quaternion.identity);
C4.rigidbody.AddForce(transform.forward * throwForce);
//animation.Play("C4Throw");
isHolding = false;
CanDetonate = true;
}
if(Input.GetKeyDown("t")(CanDetonate == true))
{
DetonationSwitch = true;
//animation.Play("PressC4Trigger");
//audio.PlayOneShot(C4TriggerAudio);
CanDetonate = false;
}
if(Input.GetKeyUp("t")(isHolding == false))
{
DetonationSwitch = false;
}
}
And here is the C4 script.
var ySpeed : float = 5;
var zSpeed : float = 2.5;
var RotateTilCollide = false;
var explosionPrefab : Transform;
//var HitWallAudio : AudioClip;
var FindTrigger : C4Throw;
function Start()
{
FindTrigger = GameObject.Find("SpawnPoint").GetComponent("C4Throw");
RotateTilCollide = true;
}
function Update ()
{
if(RotateTilCollide == true)
{
transform.Rotate(0, 45 * ySpeed * Time.deltaTime, 90 * zSpeed * Time.deltaTime);
}
if(FindTrigger.DetonationSwitch == true)
{
Destroy(gameObject);
Instantiate(explosionPrefab, transform.position, Quaternion.identity);
}
}
function OnCollisionEnter(col:Collision)
{
RotateTilCollide = false;
//audio.PlayOneShot(HitWallAudio);
Destroy (rigidbody);
}
The problem is, is when i place a C4 (or in my case a cube for a test) it will stick to the floor as it should. But when i press t to detonate it just places another C4/cube. Also I am getting a NullReference error.
This:
NullReferenceException: Object reference not set to an instance of an object
C4Script.Update () (at Assets/Resources/NewScripts/C4Script.js:20)
Any solutions?