private void Update() { if (!hasTarget) { Destroy(gameObject); return; } if (target != null) { //Destroy(gameObject); Transform centerOfTarget = target.GetComponentInChildren <MeshRenderer>().gameObject.transform; float centerToEdgeDistance = target.GetComponentInChildren <Renderer>().bounds.size.x; transform.LookAt(target.transform); //transform.localPosition += Vector3.forward * Time.deltaTime * 10f; if (Vector3.Distance(transform.position, centerOfTarget.position) > centerToEdgeDistance && target != null) { transform.position = Vector3.MoveTowards(transform.position, centerOfTarget.position, projectileSpeed); } else if (Vector3.Distance(transform.position, centerOfTarget.position) <= centerToEdgeDistance) { if (isTroop) { //Debug.Log(damage); target.TakeHit(damage, transform.localEulerAngles, "physical", 0f); //target.TakeHit(damage, transform.position); Destroy(gameObject); } //else if (isBuilding) //{ // target.GetComponent<BuildingsManager>().TakeDamage(damage); // Destroy(gameObject); // //} } } else { Destroy(gameObject); } }
// Update is called once per frame private void Update() { if (!hasTarget) { Destroy(gameObject); return; } if (target != null) { //Destroy(gameObject); Transform centerOfTarget = target.GetComponentInChildren <MeshRenderer>().gameObject.transform; float centerToEdgeDistance = target.GetComponentInChildren <Renderer>().bounds.size.x; transform.LookAt(target.transform); //transform.localPosition += Vector3.forward * Time.deltaTime * 10f; if (Vector3.Distance(transform.position, centerOfTarget.position) > centerToEdgeDistance) { transform.position = Vector3.MoveTowards(transform.position, centerOfTarget.position, projectileSpeed); } else if (Vector3.Distance(transform.position, centerOfTarget.position) <= centerToEdgeDistance) { if (!target.gameObject.GetComponent <GooDebuff>()) { target.gameObject.AddComponent <GooDebuff>(); } else { target.GetComponent <GooDebuff>().StackDebuff(); } Destroy(gameObject); } } else { Destroy(gameObject); } }
IEnumerator ShowIndication() { isRunning = true; LivingEntityManager hero; while (!Input.GetMouseButtonUp(0)) { if (currentSelection != null) { currentSelection.GetComponentInChildren <MeshRenderer>().material = defaultMat; currentSelection = null; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, heroMask)) { //Material temp; if (hit.collider.GetComponent <LivingEntityManager>()) { hero = hit.collider.GetComponent <LivingEntityManager>(); //temp = hero.GetComponentInChildren<MeshRenderer>().material; if (hero != this.GetComponent <LivingEntityManager>()) { hero.GetComponentInChildren <MeshRenderer>().material = highlightMat; currentSelection = hero; } //if (Input.GetMouseButtonUp(0)) //{ // //Debug.Log("click"); // hero.GetComponentInChildren<MeshRenderer>().material = wrongHighlighMat; // // //Deploy GOO //} } } yield return(null); isRunning = false; } if (currentSelection != null) { currentSelection.GetComponentInChildren <MeshRenderer>().material = defaultMat; while (Vector3.Distance(transform.position, currentSelection.transform.position) > 8f) { yield return(null); } StartCoroutine(CoolDownStart()); GetComponent <LivingEntityManager>().ChangeMana(-manaConsuption); if (gameObject.GetComponent <PlayerController>().lastAbility.Count < 5) { gameObject.AddComponent <BristleFuryBuff>(); } //else // gameObject.GetComponent<BristleFuryPassive>().StackDebuff(); GameObject goo = Instantiate(gooPrefab, gooSpawnPoint.position, Quaternion.identity) as GameObject; //goo.transform.position = gooSpawnPoint.position; goo.GetComponent <GooProjectile>().target = currentSelection; } else if (currentSelection == null) { if (transform.GetComponentInChildren <GooProjectile>()) { transform.GetComponentInChildren <GooProjectile>().hasTarget = false; } } }
IEnumerator ShowIndication() { LivingEntityManager hero; while (!Input.GetMouseButtonUp(0)) { if (currentSelection != null) { currentSelection.GetComponentInChildren <MeshRenderer>().material = defaultMat; currentSelection = null; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, heroMask)) { //Material temp; if (hit.collider.GetComponent <LivingEntityManager>()) { hero = hit.collider.GetComponent <LivingEntityManager>(); //temp = hero.GetComponentInChildren<MeshRenderer>().material; if (hero != this.GetComponent <LivingEntityManager>()) { hero.GetComponentInChildren <MeshRenderer>().material = highlightMat; currentSelection = hero; } //if (Input.GetMouseButtonUp(0)) //{ // //Debug.Log("click"); // hero.GetComponentInChildren<MeshRenderer>().material = wrongHighlighMat; // // //Deploy GOO //} } } yield return(null); } if (currentSelection != null) { currentSelection.GetComponentInChildren <MeshRenderer>().material = defaultMat; while (Vector3.Distance(transform.position, currentSelection.transform.position) > 8f) { yield return(null); } StartCoroutine(CoolDownStart()); GetComponent <LivingEntityManager>().ChangeMana(-manaConsuption); //else // gameObject.GetComponent<BristleFuryPassive>().StackDebuff(); GameObject laser = Instantiate(laserPrefab, transform) as GameObject; //goo.transform.position = gooSpawnPoint.position; laser.GetComponent <LaserBeam>().myPos = spawnPos; laser.GetComponent <LaserBeam>().target = currentSelection.transform; // //laser.GetComponent<LineRenderer>().SetPosition(0, spawnPos.position); //laser.GetComponent<LineRenderer>().SetPosition(1, currentSelection.gameObject.GetComponentInChildren<MeshRenderer>().transform.position); yield return(new WaitForSeconds(0.25f)); currentSelection.TakeHit(450f, transform.localEulerAngles, "magical", GetComponent <LivingEntityManager>().spellDamageAmpli); Destroy(laser, 0.5f); } else if (currentSelection == null) { //if (transform.GetComponentInChildren<LaserBeam>()) // transform.GetComponentInChildren<LaserBeam>().hasTarget = false; } }