void OnTriggerEnter(Collider col) { GameObject go = col.gameObject; if (go.CompareTag("Star")) { Player.instance.CollectStar(col); } else if (go.CompareTag("Enemy")) { //only hit enemy if player is not hurt Player player = Player.instance; if (player.state != (int)Player.State.Hurt) { Enemy enemy = M8.Util.GetComponentUpwards <Enemy>(go.transform, true); if (enemy && enemy.FSM) { enemy.FSM.SendEvent(EntityEvent.Hit); } } Vector3 n = (transform.position - go.transform.position).normalized; rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, n); } else if (go.CompareTag("TriggerSave")) { TriggerCheckpoint triggerCP = col.GetComponent <TriggerCheckpoint>(); if (triggerCP) { Player.instance.AddTriggerCheckpoint(triggerCP); } } }
public static void ChangeCheckpoint(bool isNext) { int temp_checkpoint = 0; if (lastCheckPoint == null) { lastCheckPoint = checkpoints[0]; } else { temp_checkpoint = lastCheckPoint.sequenceCheckPoint; if (isNext) { temp_checkpoint++; } else { temp_checkpoint--; } } temp_checkpoint = Mathf.Clamp(temp_checkpoint, 0, checkpoints.Count - 1); lastCheckPoint = checkpoints[temp_checkpoint]; SceneManager.ReloadScene(); }
void ToCheckpoint(TriggerCheckpoint checkpoint) { if (!roboInCamera.inView) { // navAgent.transform.position = checkpoint.forcePosRobot; navAgent.ForcePosition(checkpoint.forcePosRobot); } StartCoroutine(WaitCheckpoint()); }
void OnBodyTriggerEnter(RigidBodyController ctrl, Collider col) { if (col.gameObject.CompareTag("Star")) { mPlayer.CollectStar(col); } else if (col.gameObject.CompareTag("Enemy")) { Vector3 playerPos = mBody.transform.position; Vector3 enemyPos = col.bounds.center; Vector3 dPos = playerPos - enemyPos; //check if enemy is at bottom Vector3 localDPos = mBody.transform.worldToLocalMatrix.MultiplyVector(dPos); bool isTop = Vector3.Angle(localDPos, Vector3.up) <= 55.0f; Enemy enemy = M8.Util.GetComponentUpwards <Enemy>(col.transform, true); if (enemy) { //Debug.Log("is top: " + isTop); //kill enemy and have a free jump if (isTop && enemy.playerJumpKill) { if (enemy.FSM) { enemy.FSM.SendEvent(EntityEvent.Hit); } Vector3 localVel = mBody.localVelocity; localVel.y = enemyJumpSpeed; mBody.rigidbody.velocity = mBody.transform.rotation * localVel; mBody.jumpCounterCurrent = 1; } else if (!mPlayer.isBlinking) { Vector2 dir = dPos.normalized; Hurt(dir, false); if (enemy.state == (int)Enemy.State.Normal && enemy.FSM) { enemy.FSM.SendEvent(EntityEvent.Contact); } } } } else if (col.gameObject.CompareTag("Harm") || col.gameObject.CompareTag("Goal")) //Goal is the big monster thing { if (!mPlayer.isBlinking) { Vector2 dir = (mBody.transform.position - col.bounds.center).normalized; Hurt(dir, false); } } else if (col.gameObject.CompareTag("Death")) { mPlayer.GameOver(); } else if (col.gameObject.CompareTag("TriggerSave")) { TriggerCheckpoint triggerCP = col.GetComponent <TriggerCheckpoint>(); if (triggerCP) { mPlayer.AddTriggerCheckpoint(triggerCP); } } }
public void AddTriggerCheckpoint(TriggerCheckpoint trigger) { mLastTriggers.Add(trigger); }
void Start() { lastCheckPoint = firstCheckpoint; SceneManager.OnDie += Respawn; }