コード例 #1
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (angry && collision.gameObject.tag.Equals(player.tag))
     {
         // TODO: It's axe time
         PlayerKilledMessage message = new PlayerKilledMessage(gameObject);
         MessageCenter.Instance.Broadcast(message);
     }
 }
コード例 #2
0
	protected override void GameUpdate () 
	{
		if (updateEnemyNPC ())
		{
			return;
		}

        if (GlobalGameStateManager.PanicTree != null)
        {
            //GlobalGameStateManager.PanicTree.GetComponent<PossessableTree>().BodyParts.Trunk.GetComponent<SpriteRenderer>().color = Color.red;

            if (Vector3.Distance(transform.position, GlobalGameStateManager.PanicTree.transform.position) <= 2f && !sent)
            {
                sent = true;
                PlayerKilledMessage message = new PlayerKilledMessage(gameObject, GlobalGameStateManager.PanicTree);
                MessageCenter.Instance.Broadcast(message);

                // Find the closest respawn point
                Vector3 position = Vector3.zero;
                float distance = float.MaxValue;

                foreach(GameObject spawnPoint in GameObject.FindGameObjectsWithTag("Respawn"))
                {
                    float d = Vector3.Distance(transform.position, spawnPoint.transform.position);

                    if(d < distance)
                    {
                        d = distance;
                        position = spawnPoint.transform.position;
                    }
                }

                nextPath.transform.position = position; // new Vector3(26.81f, -2.93f);
                killSelf = true;

                return;
            }
        }

		if (investigating)
		{
			if (leaveTime <= Time.time)
			{
				investigating = false;
				killSelf = true;
				if (calledToPoint)
				{
					calledToPoint = false;
					Destroy(nextPath);
				}
				nextPath = getLeavingPath();
			}

			investigate();
		}
		
		Vector3 pathPosition = nextPath.transform.position;
		Vector3 positionNPC = transform.position;
		float step = speed * Time.deltaTime;
		
		Vector3 movement = Vector3.MoveTowards (positionNPC, pathPosition, step);
		Vector3 direction = Vector3.Normalize(movement - transform.position);
		animateCharacter(movement, pathPosition);
		
		Vector3 changeMovement = avoid (direction);

		if( changeMovement != Vector3.zero )
		{
			Vector3 newPos = Vector3.MoveTowards(positionNPC,changeMovement,step);
			determineDirectionChange(transform.position, newPos);
			transform.position = newPos;
		}
		else
		{
			determineDirectionChange(transform.position, movement);
			transform.position = movement;
		}
		
		if (movement == pathPosition)
		{
			handleSitting();
		}
	}
コード例 #3
0
	// Collision Methods

	protected override void OnCollisionEnter2D(Collision2D collision)
	{
		base.OnCollisionEnter2D (collision);

		// TODO: See if instead of checking tag if we should check active player (getPlayer()) object
		if (angry && collision.gameObject.tag.Equals(player.tag))
		{
            PlayerKilledMessage message = new PlayerKilledMessage(gameObject, collision.gameObject);
			MessageCenter.Instance.Broadcast(message);
			MessageCenter.Instance.Broadcast(new AxeManAngerChangedMessage(false));
			angry = false;
			panicTexture.renderer.enabled = false;
			killSelf = true;
		}
	}