- Home /
Question by
bearded_pete · Jan 20, 2014 at 05:02 PM ·
javascriptplayertags
Simple code is not recognizing tag anymore.
I am a novice to Unity and coding and am working on a 2D scrolling game. I have 2 codes that are triggered by the tag "Player". One that moves the enemy back on the Z axis and "stomps" it, and one that destroys the player and respawns him. They has worked numerous times. Suddenly the "Stomp" code stopped recognizing the player tag, so now only the kill/respawn code works. I've tried re-sizing the box colliders as each scrip is on a separate collider but it has no affect. What happened?
Here are the codes: Enemy:
#pragma strict
private var fall : boolean;
var Player : GameObject;
var spawnPoint : Transform;
var stomp : boolean;
function Update () {
if(stomp){
transform.position.z = 4;
transform.localScale.y /= 2;
audio.Play();
fall = true;
gameObject.GetComponent(PlatformMover).step = 0.0;
stomp = false;
}
if(fall){
transform.position.y -= 0.05;
}
if(transform.position.y < -25){
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider){
if(!stomp){
if(other.tag == "Player"){
Destroy(other.gameObject);
var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
var sf = Camera.main.GetComponent(SmoothFollow2);
sf.target= P.transform;
}
}
}
Stomp:
#pragma strict
function OnTriggerEnter(other : Collider){
if(other.tag == "Player"){
transform.root.gameObject.GetComponent(Enemy).stomp = true;
}
}
Comment