Hello,
I have a simple tower defence game, with a path leading from one end of the scene, to another end - the enemy follow this path using waypoints. The user can place a turret anywhere around the scene at the moment. But is it possible not to put a turret on the path? My path uses a different terrain texture (rock) where as my 'placeable' terrain is grass - how would I tell unity not to allow the turret to be placed on anything with the texture 'rock'?
To place a turret, I use a simple raycast to determine where the user is clicking and then initiate a prefab on that position (snippet) :
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
var layerMask = 1 << 8;
if (chooseLocation) {
layerMask = ~layerMask;
Physics.Raycast (ray, hit, 500, layerMask);
currentObj.Translate((Vector3(hit.point.x, currentObj.position.y, hit.point.z) - currentObj.position) * Time.deltaTime *followSpeed);
}
if (Input.GetButtonDown("Fire1")){ //Input.GetMouseButton(0)
chooseLocation = false;
// maybe a : if(terrain texture = grass?
}
// Cancel Selection \\
if(Input.GetButtonDown("Fire2") && currentObj.gameObject){
objLimit[currentSelected] ++;
chooseLocation = false;
Destroy(currentObj.gameObject);
}
}
Maybe I dont have to use terrain texture? Is there another way to do it?
Thanks folks!