- Home /
Question by
Rebel8909 · Aug 01, 2014 at 05:57 AM ·
javascriptraycastvariabletag
How to assign a Variable with a Raycast
So in my script I am using Raycast to identify an object when clicked. So far it detects objects with a tag of "Card" (I have some more code in it but it doesn't affect it yet) what I want it to do is to assign said object as a variable called Card for later use.
Here's the code:
#pragma strict
var Tile : GameObject;
var Check : boolean = false;
var Card : GameObject;
function Update(){
if(Input.GetMouseButton(0)){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,hit)){
if(hit.collider.tag == "Card"){
Debug.Log(hit.collider.name);
Check = true;
Card == Object;
}
}
}
Now how can I use the Raycast to take an object Tagged "Card" and assign that GameObject to the Var Card.
Comment
Card = hit.gameObject;
or
Card = hit.collider.gameObject;
Your answer
Follow this Question
Related Questions
Switch GameObjects Tags with javascript 1 Answer
Bug/Error in script CollectPapers 0 Answers
Changing variable in a script of a game object hit with raycast 1 Answer
casting a raycast from the raycast hit.point 1 Answer
Gun Script Help 2 Answers