// Update is called once per frame void Update() { #if UNITY_EDITOR || UNITY_STANDALONE if (Input.GetKeyDown(KeyCode.F)) { fire = true; EventService.Instance.GetEvent <FireChangeEvent>().Publish(true); } else if (Input.GetKeyUp(KeyCode.O)) { fire = false; EventService.Instance.GetEvent <FireChangeEvent>().Publish(false); } #endif #if UNITY_IPHONE || UNITY_ANDROID if (btnFire.IsPressed()) { if (Time.timeScale == 0) { return; } fire = true; EventService.Instance.GetEvent <FireChangeEvent>().Publish(true); } else { fire = false; EventService.Instance.GetEvent <FireChangeEvent>().Publish(false); } #endif if (fire) { if (Time.time > lastFireTime + 1f / frequency) { lastFireTime = Time.time; GameObject bulletObj = (GameObject)Instantiate(bulletPrefab, spawnPoint.position, spawnPoint.rotation); SimpleBullet bullet = bulletObj.GetComponent <SimpleBullet>(); Quaternion q = Quaternion.Euler(Vector3.zero); RaycastHit hitinfo = transform.GetComponent <BulletRaycast>().GetHitInfo(q); if (hitinfo.transform != null && hitinfo.distance <= bullet.distance) { if (hitinfo.transform.tag == "Enemy") { //hit the enemy Vector3 force = transform.forward * 10 / frequency; hitinfo.rigidbody.AddForce(force, ForceMode.Impulse); // bullet.distance = hitinfo.distance; EventService.Instance.GetEvent <EnemyStateChangeEvent>().Publish(AnimState.take1, hitinfo.transform.GetComponent <EnemyController>().EnemyId); hitinfo.transform.GetComponent <EnemyController>().onDamage(bullet.damage, hitinfo.point); } else { Debug.Log("hitinfo's name is " + hitinfo.transform.gameObject.name); } bullet.distance = hitinfo.distance; } } } }
// Update is called once per frame void Update() { if (chopOnHand) { #if UNITY_EDITOR || UNITY_STANDALONE if (Input.GetKeyDown(KeyCode.F)) { fire = true; } else if (Input.GetKeyUp(KeyCode.F)) { fire = false; } #elif UNITY_IPHONE || UNITY_ANDROID if (btnFire.IsPressed() && !fire) { EventService.Instance.GetEvent <HeroStateChangeEvent>().Publish(AnimState.attack, transform.GetComponent <HeroController>().heroId); } if (!btnFire.IsPressed() && fire) { EventService.Instance.GetEvent <HeroStateChangeEvent>().Publish(AnimState.idle, transform.GetComponent <HeroController>().heroId); } if (btnFire.IsPressed()) { if (Time.timeScale == 0) { return; } fire = true; EventService.Instance.GetEvent <FireChangeEvent>().Publish(true); } else { fire = false; EventService.Instance.GetEvent <FireChangeEvent>().Publish(false); } #endif if (fire) { if (Time.time > lastFireTime + 1f / frequence) { lastFireTime = Time.time; Debug.Log("current rotation is: " + transform.rotation.eulerAngles); Quaternion r = Quaternion.AngleAxis(chopAngles / 2f, Vector3.up) * transform.rotation; Vector3 rPoint = r * Vector3.forward * distance + transform.position; Debug.DrawLine(transform.position, rPoint, Color.red, 10f); Quaternion l = Quaternion.AngleAxis(chopAngles / 2f, Vector3.down) * transform.rotation; Vector3 lPoint = l * Vector3.forward * distance + transform.position; Debug.DrawLine(transform.position, lPoint, Color.green, 10f); for (int i = EnemyManager.Instance.Enemies.Count - 1; i >= 0; i--) { if (EnemyManager.Instance.Enemies[i] != null && Helper.isINTriangle(EnemyManager.Instance.Enemies[i].transform.position, transform.position, lPoint, rPoint)) { Debug.Log("hit enemy!!!!!!!!!!"); Vector3 force = transform.forward * 3; EnemyManager.Instance.Enemies[i].GetComponent <Rigidbody>().AddForce(force, ForceMode.Impulse); // EventService.Instance.GetEvent<EnemyStateChangeEvent>().Publish(AnimState.take, enemy.EnemyId); EnemyManager.Instance.Enemies[i].onDamage(damage, EnemyManager.Instance.Enemies[i].transform.position); } } // foreach(EnemyController enemy in EnemyManager.Instance.Enemies) // { // if (enemy != null && Helper.isINTriangle(enemy.transform.position, transform.position, lPoint, rPoint)) // { // Debug.Log("hit enemy!!!!!!!!!!"); // Vector3 force = transform.forward * 3; // enemy.rigidbody.AddForce(force, ForceMode.Impulse); // //// EventService.Instance.GetEvent<EnemyStateChangeEvent>().Publish(AnimState.take, enemy.EnemyId); // enemy.onDamage(damage, enemy.transform.position); // } // } } } } }
void Update() { UpdateRocker(); if (!isPlayer) { return; } if (automatic) { return; } #if UNITY_EDITOR || UNITY_STANDALONE if (Input.GetKeyDown(KeyCode.F)) { isFired = true; EventService.Instance.GetEvent <FireChangeEvent>().Publish(true); } else if (Input.GetKeyUp(KeyCode.O)) { isFired = false; EventService.Instance.GetEvent <FireChangeEvent>().Publish(false); } #else if (btnFire.IsPressed()) { if (Time.timeScale == 0) { return; } isFired = true; EventService.Instance.GetEvent <FireChangeEvent>().Publish(true); } else { isFired = false; EventService.Instance.GetEvent <FireChangeEvent>().Publish(false); } #endif #if UNITY_EDITOR || UNITY_STANDALONE if (Input.GetKeyDown(KeyCode.A)) { //turn to left dir += Vector3.left; } if (Input.GetKeyDown(KeyCode.W)) { dir += Vector3.forward; } if (Input.GetKeyDown(KeyCode.S)) { dir += Vector3.back; } if (Input.GetKeyDown(KeyCode.D)) { dir += Vector3.right; } if (Input.GetKeyDown(KeyCode.T)) { dir = Vector3.zero; } dir = dir.normalized; #else // Vector2 pos = joystick_left.getPositions(); Vector2 pos = joystickLeft.position; dir = new Vector3(pos.x, 0, pos.y).normalized; #endif }