I'm actually working on a word search like game.
But i'm having issues when i want to select instantiate gameObjects on a grid.
as i saw on unity doc, i used raycast to check which collider has been hit, and do some logic.
So i wrote this:
void Update(){
if (Input.GetMouseButtonDown(0))
{
Ray ray;
RaycastHit hit;
GameObject current;
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit))
{
if (hit.collider.tag == "tile")
{
//Do some logic
}
}
}
After that, i used this:
Vector3 forward = transform.TransformDirection(Vector3.forward) * 50;
Debug.DrawRay(transform.position, forward, Color.green);
to display raycasts when i run the game.
So when i click with my mouse, a single ray is fired.
Normally it should fire a lot more. But i don't know why it's shooting just one ray.
Also,
Input.mousePosition
does not seem to work. the ray just fires at the center of my screen.
How can i fix that? Is there other method than raycast?
Thanks a lot.