// Update is called once per frame void Update() { if (clickable) { if (Input.GetMouseButtonDown(0)) { //take the pixel clicked in the screen image and convert it to a ray in world space Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); selectedPos = Input.mousePosition; RaycastHit hitInfo = new RaycastHit(); //cast the ray and return true if it collided with some GameObject's collider component if (Physics.Raycast(ray, out hitInfo)) { //we know that if the ray collides with something we want, it is the component //of an overall object (ie the ray hits turretBody, part of a Turret gameObject) if (selected == selectedState.none) { selectedObject = hitInfo.collider.gameObject.transform.parent.gameObject; } if (selectedObject.tag == "Tile") { selected = selectedState.tile; clickable = false; } if (selectedObject.tag == "Turret") { selected = selectedState.turret; //clickable = false; } if (selectedObject.tag == "Creep") { selected = selectedState.creep; } } else { selected = selectedState.none; } } } }
public void changeState(selectedState newState) { currentState = newState; switch (currentState) { case selectedState.UNSELECTED: enemy.characterObject.GetComponent <MeshRenderer>().material.SetColor("_Color", Color.white); break; case selectedState.HOVERED: enemy.characterObject.GetComponent <MeshRenderer>().material.SetColor("_Color", Color.grey); break; case selectedState.SELECTED: enemy.characterObject.GetComponent <MeshRenderer>().material.SetColor("_Color", Color.black); break; default: break; } ; }