- Home /
Change crosshair text when hitting a trigger
I was looking for a way to change the texture of a cross-hair when my ray hit a trigger. the code I have right now only changes when it hits a collider.
I assume it would be helpful to show what I have so far...
var crosshairCantRotate : Texture2D; var crosshairCanRotate : Texture2D; var position : Rect; function Start() { position = Rect( ( Screen.width - crosshairCantRotate.width ) / 2, ( Screen.height - crosshairCantRotate.height ) / 2, crosshairCantRotate.width, crosshairCantRotate.height ); Screen.showCursor = false; }
function OnGUI () { var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, 10)) { GUI.DrawTexture(position, crosshairCanRotate); print ("Hit something"); } else GUI.DrawTexture(position, crosshairCantRotate); print("Not Hitting Something"); }
I am by far no expert in raycasting, but I have never heard that raycasts can be used with triggers.
Your answer
Follow this Question
Related Questions
Raycast questions 1 Answer
disable script on trigger 1 Answer
Parenting Bullet Holes? 1 Answer
RayCast Hit 2 Answers
Raycasts not working on triggers. 2 Answers