the mouse touch system, I want to click the mouse on an object

como colocar sistema de toque do mouse, quero que ao clicar com o mouse num objeto ele gerar pontos como faço isto no script.

like putting the mouse touch system, I want to click the mouse on an object to generate points as he do it in the script.

i didnot understand, maybe something like:

//here left click on mouse
if(Input.GetButtonDown("Fire1"))
{
//pos is mouse position
Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
//hit is collider, that would be hitted with ray
RaycastHit2D hit = Physics2D.Raycast (pos, Vector3.forward);
//and then make something with hit :)
if (hit !=null) {..........}
}

Hi thanks but did not work, he came under the wheel Foot Unity, script errors. you could send me but details by email. so is meljor of comprieender. orkyys@gmail.com

add in scene something with collider2d and try this

    RaycastHit2D hitted;
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            hitted = Physics2D.Raycast(pos, Vector3.forward);
            if (hitted.collider != null)
                Debug.Log(hitted.collider.gameObject.name);
        }
    }

Look boy, did not work still appears under the errors Unity footer, here is not like sending pictures for you to see better. help me. I really want to do this game, and so easy, assemble scenes, and it is so difficult to program. Do not give up on me not, continues to help me go to work one day. I want to monetize it but TA difficult. And it takes a long time. Do you have a blog, email anything. If you want to inform. All help and welcome.

create c# script, name it: hitClick
open it, delete all in it and add this code, i have tested it. Maybe you are doing something wrong, make screenshot of the error

using UnityEngine;
using System.Collections;

public class hitClick : MonoBehaviour {
    RaycastHit2D hitted;
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            hitted = Physics2D.Raycast(pos, Vector3.forward);
            if (hitted.collider != null)
                Debug.Log(hitted.collider.gameObject.name);
        }
    }
}

set tag of hearts to heart (or something, that you will and change line hitted.collider.gameObject.tag == “heart”)

using UnityEngine;
using System.Collections;

public class hitClick : MonoBehaviour {
    RaycastHit2D hitted;
public int score;
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            hitted = Physics2D.Raycast(pos, Vector3.forward);
            if (hitted.collider != null)
if (hitted.collider.gameObject.tag == "heart") {
score = score + 10;
}
                Debug.Log(hitted.collider.gameObject.name);
        }
    }
}

and hearts should have collider2D

young man you mean coliider2d, that is 2D format. um ok and really this and 3D that I did. I have to do in 2D format.

hi let me tell you but one thing. I want to make 3D so how do I change the script …

I will try to use adobe illustrator. to create 2D.

i didnot used 3d. I think, you can try delete 2D from script. I mean RaycastHit hitted; hitted = Physics.Raycast(pos, Vector3.forward);

Is it because I’m using Unity Personal he not all complete.

RaycastHit hitted; hitted = Física.Raycast(post, Vector3.para a frente);
I have to put here