Hello Guest

Author Topic: OnTriggerEnter is not running! Need help with collision.  (Read 7032 times)

tunahantolga

  • Newbie
  • *
  • Posts: 12
    • View Profile
OnTriggerEnter is not running! Need help with collision.
« on: July 27, 2013, 09:35:40 pm »

0
I am making jumping game and I have a problem.(I am using Unity 4 and 2D Toolkit.) I have a 3 sprite in scene.First layer, second shaman(main character), third gold. I want to collision shaman and gold.When shaman touched gold, I want to destroy gold.

Here is the code:

void OnTriggerEnter(Collider collision) {
 
Destroy(collision.gameObject);
 
if (collision.gameObject.tag == "goldshaman") {
Destroy(gameObject);
}

}

I made a shaman tag is goldshaman and shaman and gold is own to sphere collider. Also is trigger marked.(gold and shaman). Shaman and gold is same z axis.Gold is moving and touched shaman but gold is not destroy.

Simply can't work why?

Please help guys.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: OnTriggerEnter is not running! Need help with collision.
« Reply #1 on: July 27, 2013, 10:47:20 pm »
How are you moving your character?

tunahantolga

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: OnTriggerEnter is not running! Need help with collision.
« Reply #2 on: July 28, 2013, 10:48:09 am »
Gold has a other C# code. And I changed goldWiggle value and goldSpeed. Example goldWiggle x= 3, y=0, goldSpeed=1.
So gold pass through shaman but gold is not destroy.

Here is the code:

    public Vector3 initPas;
    public Vector2 goldWiggle;
    public float goldSpeed;

   // Use this for initialization
   void Start () {
        initPas = transform.position;
   }
   
   // Update is called once per frame
   void Update () {
        transform.position = initPas + new Vector3(Mathf.PingPong(Time.time * goldSpeed, goldWiggle.x), 0, 0);
   }

tunahantolga

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: OnTriggerEnter is not running! Need help with collision.
« Reply #3 on: July 28, 2013, 11:38:19 am »
I add a Rigidboy(use gravity and is kinematic) on Gold and Shaman. After solved a problem.