I have an object tagged as “Buster” flying through a trigger that should detect objects with the tag “Buster” and respond, but it does not. I have seen in other similar questions asked here the solution was found when they added a rigidbody to one of the objects. So I have added a rigidbody to the “Buster”. Raycasts Hit Trigger is true. The trigger is a sphere collider with Is Trigger set to true.
This is the trigger script:
#pragma strict
public var HP : int;
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider) {
if(other.tag == "Buster"){
HP = (HP -1);
}
}
This is the “Buster” script:
#pragma strict
private var left : boolean;
public var time : float;
public var speed : float;
private var counter : float;
public var xPosition : float;
public var yPosition : float;
function Start () {
transform.position.x += xPosition;
transform.position.y += yPosition;
left = true;
counter = 0;
}
function Update () {
if (left) {
if (time > counter){
transform.position.x -= speed;
counter++;
}
else {
Destroy(this.gameObject);
}
}
else {
if (time > counter){
transform.position.x += speed;
counter++;
}
else {
Destroy(this.gameObject);
}
}
}