Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Player sometimes kills enemy, and sometimes they both die... WHY?

$
0
0
(UPDATE: the problem might have something to do with the isGrounded script. I am continually dying when I'm in the middle of jumping when trying to kill a different enemy. This is just food for thought, perhaps it's useless. Anyways, thanks again if you can help) Here is a video showing what happens: http://www.youtube.com/watch?v=sX15OWZLA6g&feature=youtu.be Here is my enemy script: var Player : GameObject; var spawnPoint : Transform; var stomp : boolean; var thePrefab: GameObject; private var player : PlayerScript; function Start(){ player = GameObject.FindWithTag("Player").GetComponent(PlayerScript); } function Update () { if(stomp){ stomp = false; Destroy(gameObject); transform.position.z = 3; var thePrefab : GameObject = Instantiate(thePrefab, transform.position, Quaternion.identity); Destroy(thePrefab.gameObject, 1.5); } } function OnTriggerEnter(other : Collider){ if(!stomp){ if(other.tag == "Player"){ if(player.Diamond == true){ Destroy(gameObject); var thePrefab : GameObject = Instantiate(thePrefab, transform.position, Quaternion.identity); Destroy(thePrefab.gameObject, 5); } if(player.Diamond == false){ Destroy(other.gameObject); var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity); var cf = Camera.main.GetComponent(CameraFollow); cf.player = P; } if(player.Pick == true){ player.Pick = false; return; } } } } Here is my player script: var pick_pref : Transform; var speed : int = 5; var jumpSpeed: float = 8; var isgrounded : boolean = true; var isRight : boolean = true; var killEnemy: boolean = true; var Diamond : boolean; var Pick : boolean = false; var colorFirst : Color = Color.white; var colorSecond : Color = Color.white; var colorThird: Color = Color.white; var colorFourth : Color = Color.white; var duration : float; var Regular : Texture2D; var Star : Texture2D; var PowerUp : Texture2D; var theParticle : GameObject; private var moveDirection : Vector3 = Vector3.zero; function Start () { } function Update () { if(Diamond == true){ renderer.material.mainTexture = Star; var lerp : float = Mathf.PingPong (Time.time, duration) / duration; renderer.material.color = Color.Lerp (colorFirst, colorSecond, lerp); renderer.material.color = Color.Lerp (colorThird, colorFourth, lerp); var theParticle : GameObject = Instantiate(theParticle, Vector3(transform.position.x, transform.position.y, transform.position.z -1), Quaternion.identity); Destroy(theParticle.gameObject, 0.3); } if(Diamond == false){ renderer.material.color = Color.white; renderer.material.mainTexture = Regular; } } function OnCollisionEnter(theCollision : Collision){ if(theCollision.gameObject.tag == "floor" || "pTrig"){ isgrounded = true; } if(theCollision.gameObject.tag == "Mover"){ transform.parent = theCollision.transform; } } function OnCollisionExit(theCollision : Collision){ if(theCollision.gameObject.tag == "floor" || "rTrig"){ isgrounded = false; } if(theCollision.gameObject.tag == "Mover"){ transform.parent = null; } } function OnTriggerEnter(other: Collider){ if(other.tag == "Pick"){ Pick = true; } if(other.tag == "enemy"){ renderer.material.mainTexture = Regular; } if(other.tag == "Diamond"){ if(other.tag == "enemy"){ Destroy(gameObject); } Diamond = true; yield WaitForSeconds(13); Diamond = false; } } The error I get, when both the player and enemy die is: MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. CameraFollow.Update () (at Assets/Scripts/CameraFollow.js:4) my camera script is: var player : GameObject; function Update () { this.gameObject.transform.position = new Vector3(player.gameObject.transform.position.x, this.gameObject.transform.position.y, this.gameObject.transform.position.z); } What on Earth am I doing wrong? Why is my character dying at all, when the diamond power is supposed to make her kill all enemies? Thanks for the help.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>