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. Code (javascript): 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. Code (javascript): 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: Code (csharp): NullReferenceException: Object reference not set to an instance of an object C4Script.Update () (at Assets/Resources/NewScripts/C4Script.js:20) Any solutions?
I'm probably wrong, but is "gameObject" in the C4 script actually somewhere defined? Perhaps that's the reason for the Null..Exception.
Can't test it myself, so my next assumtion would be that either ^that line doesn't get the object you are looking for or that you should try something like... Destroy(FindTrigger.gameObject); or whatever else the right way is to get the gameObject for FindTrigger. (I'm just throwing out ideas so sorry, if the problem isn't in those two lines)
When i double click the error in the compiler, it opens unitron and that line is highlighted. So that is the the line with the error. btw im not sure what happened with the space between o and w in throw.
Not sure which line you are referring to, but you should probably make sure that it's doing what it is supposed to.
I will see if I can get hold of the writ of the script. I think it's something to do with the detonation switch variable, i can't work out what it does.