Search Unity

Setter on Collision2D.isTrigger

Discussion in '2D' started by ekeskin, May 23, 2014.

  1. ekeskin

    ekeskin

    Joined:
    May 23, 2014
    Posts:
    1
    Hi,

    i'm trying to achieve change object's isTrigger option on click. This is my update and setColl functions.

    Code (csharp):
    1. void Update () {
    2.         if (Input.touchCount == 1  Input.GetTouch(0).deltaTime > 1f  BalderBrain.isGameOn)
    3.         {
    4.             Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
    5.             Vector2 touchPos = new Vector2(wp.x, wp.y);
    6.             if (collider2D == Physics2D.OverlapPoint(touchPos))
    7.             {
    8.                 setColl();
    9.                 this.rigidbody2D.gravityScale = 1;
    10.                 this.gameObject.tag="Dusuyor";
    11.                 Invoke("DestroyMe",2f);
    12.             }
    13.         }
    14.     }
    Code (csharp):
    1. void setColl(){
    2.         this.gameObject.collider2D.isTrigger = true;
    3.     }
    this doesn't work anyway. gravityScale, tag and Invoke lines are working just fine. But i cannot change objects trigger option. with or without gameObject.