private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { if (playManager.GainResource(this.type, this.position)) { Destroy(gameObject); } } }
private IEnumerator DiedAnim() { playManager.SendEvent(PlayEventType.PLAYER_KILL); playManager.SendEvent(PlayEventType.PLAYER_KILL_GIANT); // scaleCtrlPosY = transform.position.y + 1; speed = Vector3.zero; yield return(new WaitForSeconds(2)); deathTargetScale = new Vector3(0f, 0f, 0f); int goldNum = 10; while (goldNum-- > 0) { playManager.GainResource(ResourceType.GOLD); } }
// Update is called once per frame void FixedUpdate() { if (health.IsAlive()) { if (player == null) { player = GameObject.FindGameObjectsWithTag("Player")[0]; return; } // movement transform.position += transform.forward * speed * Time.fixedDeltaTime; if (Vector3.Dot(transform.forward, (player.transform.position - transform.position).normalized) > torqueThreshold) { //speed up speed += maxAcc * Time.fixedDeltaTime; } else { //slow down speed -= maxAcc * Time.fixedDeltaTime; } speed = Mathf.Clamp(speed, size * maxSpeed / 2, maxSpeed * size); torque = maxTorque * (1 - speed / maxSpeed); Quaternion TargetRotation = Quaternion.LookRotation(player.transform.position - transform.position + Vector3.up * 2, Vector3.up); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * torque * size); // attack if (currentCD < attackCD) { if (DistanceToPlayer() < 4) { currentCD += Time.fixedDeltaTime; } else { currentCD += Time.fixedDeltaTime * 0.3f; } } else { DoAttack(); health.DoAttack(5); currentCD -= attackCD; } } else { if (deathMutex) { deathMutex = false; // Do death playManager.SendEvent(PlayEventType.PLAYER_KILL); playManager.SendEvent(PlayEventType.PLAYER_KILL_LAZER); int goldNum = 10; while (goldNum-- > 0) { playManager.GainResource(ResourceType.GOLD); } } } }