Question by
liu12010 · Jan 08, 2016 at 03:19 PM ·
instantiateontriggerenterontriggerexit
OnTriggerExit happens when a rigibody instantiate
hello,I got a weird problem. When my character throw an axe ,OnTriggerExit happen and OnTriggerEnter happen soon.I don't know why OnTriggerExit happen and it makes the OnTriggerEnter happen soon when I throw(Instantiate) an axe. here is about the OnTriggerEnter and OnTriggerExit
var Vikin:GameObject;
var enemy:GameObject;
static var firestatue:boolean;
var sta:boolean;
var target1:GameObject;
var target2:GameObject;
var target3:GameObject;
var crosshair:GameObject;
var startfight:AudioClip;
var fighting:AudioClip;
var magicPoint:Transform;
var magic:GameObject;
function Start () {
}
function Update () {
}
function OnTriggerEnter(other : Collider)
{
if(other.tag=="Viking"&&firestatue==false)
{
firestatue=true;
target1.GetComponent.<Animation>().Play("Target_Up");
GameObject.Find("Vikin").GetComponent.<AudioSource>().PlayOneShot(startfight);
Instantiate(magic,magicPoint.position,magicPoint.rotation);
yield WaitForSeconds(1);
Debug.Log(other.gameObject.name);
Debug.Log(firestatue);
}
}
function OnTriggerExit(other : Collider)
{
if(other.tag=="Viking"&&firestatue==true)
{
firestatue=false;
target1.GetComponent.<Animation>().Play("Target_Down");
GameObject.Find("Vikin").GetComponent.<AudioSource>().Stop();
Debug.Log("TriggerExit");
}
}
and here is about the Instantiate of the axe
#pragma strict
var axeRigi:Rigidbody;
var yThrower:float;
var zThrower:float;
var throwAudio:AudioClip;
function Start () {
}
function Update () {
if(Input.GetButtonDown("Fire1"))
{
var axe1=Instantiate(axeRigi,transform.position,transform.rotation);
axe1.GetComponent.<Rigidbody>().velocity=transform.TransformDirection(Vector3(0,yThrower,zThrower));
Physics.IgnoreCollision(axe1.GetComponent.<Collider>(),transform.root.GetComponent.<Collider>());
GetComponent.<AudioSource>().PlayOneShot(throwAudio);
}
}
the tag "Viking" is on my character ,of course the axe's tag is "tag_axe" not "Viking" plz somebody help me it's confused me so much
Comment