Search Unity

2d game kit asset, raycasting problem. HELP!

Discussion in '2D' started by celineeetao, Mar 23, 2018.

  1. celineeetao

    celineeetao

    Joined:
    Feb 10, 2018
    Posts:
    2
    Hi,
    I'm a newbie to Unity. I'm currently using the 2d game kit for our main character. I also created a simple raycast script, (let's make it simple for now), that basically has one update function to detect a click and destroy the clicked object:

    void Update () {
    if (Input.GetMouseButtonDown(0)){
    RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)), Vector2.zero);

    if(hit.collider != null)
    {
    Debug.Log ("Target Position: " + hit.collider.gameObject.name);
    GameObject.Find (hit.collider.gameObject.name).SetActive (false);
    }
    }
    }

    This script works perfectly fine when I removed the "CharacterController2D.cs" script from 2d game kit. But I can't detect what exactly is wrong with that script and how to fix it?

    Any help would be greatly appreciated. thank you!!
     
  2. celineeetao

    celineeetao

    Joined:
    Feb 10, 2018
    Posts:
    2
    This is the script that's giving me trouble.
    When I commented out m_Rigidbody2D = GetComponent<Rigidbody2D>(); the raycast works

    so weird.... help!
     

    Attached Files:

  3. dragontooth363

    dragontooth363

    Joined:
    Jan 3, 2019
    Posts:
    1
    I am doing the 2D game Kit platformer and I was struggling to find the Tile Palette because it wasn't where it usually is so I don't know what to do help plz
     
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Put your code in code tags please, otherwise there is no fun in reading code or have to download files we don't know where they are comin from.
     
    eses likes this.