'How to focus Camera on enemy grid for a specific seconds?
I am making a turn based game. I have two different tile grids. When it's player's turn, the Camera is focused on the enemy's grid to select a tile to attack. When it's computer's turn the Camera will focus on player's grid to select a random tile to attack.
Because the player has to give an Input (from mouse) to attack a tile, the Camera will be focused on the enemy's grid. However, when the computer attacks, the Camera moves very fast on the player's grid and back to the enemy's (in less than a second). What i want is to wait a few seconds so that the player can see where the attack happened. The Camera position changes inside the function Update(). Here is part of my code for that:
private void Update()
{
if (playerTurn)
{
Camera.main.transform.position = new Vector3(40, 12.5f, -6);
playerAttack(); //Select tile to attack
}
else
{
Camera.main.transform.position = new Vector3(-1.7f, 12.5f, -6);
computerAttack(); //Select one random tile
}
}
Solution 1:[1]
You can use IEnumerator
private void Update()
{
if (playerTurn)
{
Camera.main.transform.position = new Vector3(40, 12.5f, -6);
StartCoroutine(WaitAndGO(2))
}
else
{
Camera.main.transform.position = new Vector3(-1.7f, 12.5f, -6);
computerAttack(); //Select one random tile
}
}
private IEnumerator WaitAndGO(float waitTime)
{
yield return new WaitForSeconds(waitTime);
playerAttack();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lelouch kun |
