Hey there,
I created a grid:
using UnityEngine;
using System.Collections;
public class Grid : MonoBehaviour {
public Transform CellPrefab;
public Vector3 Size;
// Use this for initialization
void Start () {
CreateGrid ();
}
// Update is called once per frame
void CreateGrid () {
for (int x = 0; x < Size.x; x++) {
for (int z = 0; z < Size.z; z++) {
Instantiate (CellPrefab, new Vector3 (x, 0, z), Quaternion.identity);
}
}
}
}
And I want to create cubes on top of the cells when i click them , therefor i used a raycasthit and the name of the hit object.
The Problem i have is that im somehow not able to click on the cells.
It works if i use a Plane and try to click on it but not on the cells.
void Update () {
if (Input.GetMouseButtonDown (0)) {
RaycastHit hit;
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
Debug.Log("1");
if (Physics.Raycast(ray, out hit) && hit.transform.name=="Cell"){
//Instantiate (CannonPrefab);
Debug.Log("hit");
}
}
}
Im aware that the current script does not actual would spawn each cannon in each cell of the grid but i dont want to go on while i even cant click on the cells.
Does anyone have a clue why it wont work like this?