- Home /
Raycast and Hit Problem
Hi Community,
I have a little Problem. First of all, I want to show you my little script
#pragma strict
var test : GameObject;
function Start () {
renderer.enabled = false;
}
function Update (){
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit))
{
if(hit.collider.gameObject == test);
Debug.Log("Console Text");
}
}
So I have two Problems : First, if I place the script on a Camera, I have to add a Renderer. But I only want, that the 'test' Object can be used by the Raycast.
Second : If I'm floating with my mouse over the 'test' Object, the Debug Log is shown. I want, that the Log is only shown, if I'm hitting the Object.
At last, sorry for my bad English and thank you for help !
What does "if I'm hitting the Object" mean? Click on the object? Given what I think you are trying to do here, you might take a look at the On$$anonymous$$ouse* functions...probably On$$anonymous$$ouseDown().
Your answer
Follow this Question
Related Questions
Use ray cast against objects but avoid colliding against other objects 2 Answers
Raycast/Non-Physics Collider Discrepancy 0 Answers
Extend the Collider When Picking Up Objects 0 Answers
Is Object At Location? 3 Answers
Mouse clicking on an object (Raycast.hit) for another object to connect to it? 0 Answers