x


C Sharp Clickable Object

i have a code in java that can select targets with my mouse, but it's in java

if (Input.GetMouseButtonDown(0))
        {
           var hit : RaycastHit;
           var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
           if (Physics.Raycast (ray, hit, 100.0))
           {
                 myTarget = hit.collider.gameObject;
                 if(myTarget.tag=="tagOfTheObject")
              { 
                 //DO STUFF
              }
           }
       }

could someone tell me how to convert this to c sharp? i tired to do it my self and i failed i found a reference to it on 125This website125

but i doesn't tell me how to edit the origin of the point wich in this case it would be my mouse. Can someone help me ?

more ▼

asked Nov 05 '11 at 05:31 PM

Babilinski gravatar image

Babilinski
84 40 42 43

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    void Awake() {
        if (Physics.Raycast(ray, 100))
            print("Hit something");

    }
}
more ▼

answered Nov 05 '11 at 05:37 PM

Babilinski gravatar image

Babilinski
84 40 42 43

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1536
x297
x226
x28
x25

asked: Nov 05 '11 at 05:31 PM

Seen: 802 times

Last Updated: Nov 05 '11 at 05:37 PM