- Home /
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 ?
Comment
Best Answer
Answer by Babilinski · Nov 05, 2011 at 05:37 PM
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");
}
}
Your answer
Follow this Question
Related Questions
Making own character clickable 1 Answer
Can someone help me convert this camera controller to c# script 1 Answer
Converting C# script to javascript 0 Answers
clickable object 1 Answer