// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mouseClick = Input.mousePosition; Ray ray = myCamera.ScreenPointToRay(mouseClick); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Enemy") { hit.transform.GetComponent <Enemy>().TakeDamage(20); } if (hit.transform.tag == "TowerPosition") { if (myPurse.PlaceTower(500)) { Instantiate(tower, hit.transform.position, Quaternion.identity, towerParent); Destroy(hit.transform.gameObject); } } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mouseClick = Input.mousePosition; //Debug.Log(mouseClick); Ray ray = myCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { print("I'm looking at " + hit.transform.name); if (hit.transform.tag == "EasyEnemy") { hit.transform.GetComponent <Enemy>().TakeDamage(20); } } else { print("I'm looking at nothing!"); } if (hit.transform.tag == "TowerPosition") { if (myPurse.PlaceTower(500)) { Instantiate(tower, hit.transform.position, Quaternion.identity, towerParent); Destroy(hit.transform.gameObject); } //Debug.Log(hit.transform.name + " Hit!"); } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mouseClick = Input.mousePosition; //Debug.Log(mouseClick); Ray ray = myCamera.ScreenPointToRay(mouseClick); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Enemy") { hit.transform.GetComponent <Enemy>().TakeDamage(20); } if (hit.transform.tag == "TowerPosition") { //Debug.Log(hit.transform.name + " Hit!"); if (myPurse.PlaceTower(500)) { Instantiate(tower, hit.transform.position, Quaternion.identity, towerParent); Destroy(hit.transform.gameObject); } } } // print("I'm looking at " + hit.transform.name); //else //print("I'm looking at nothing!"); } //Spawn jellyfish randomly int num = Random.Range(1, 3000); if (num > 0 && num < 6) { //Instantiate(jelly, transform.tag.position, ) } }