i am new to raycast concept,Anybody is here plz explain me the following all lines.
var hit:RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray,hit,100.0)) {
print("I'm first cube!");
}
i am new to raycast concept,Anybody is here plz explain me the following all lines.
var hit:RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray,hit,100.0)) {
print("I'm first cube!");
}
Here you go:
var hit:RaycastHit;
Declare a RaycastHit variable named hit. Don't assign anything to this, it's unnecessary as the raycast will do that for you.
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Find the ray which goes through where the mouse is on the screen. This matters because the view rom a camera isn't flat, the top left of the screen points in a different direction to the bottom right.
if (Physics.Raycast (ray,hit,100.0)) {
Fire the ray into the scene. If it hits something, the function will return true, and hit will be assigned to with the information about what was hit.
print("I'm first cube!");
This prints stuff!