So i'm trying to set player position with GoOutsideScript. In my scene i have 2 game object to and it's called ExitPoint, and EnterPoint.
The script goes like this :
public Animator FadeAnimation;
public GameObject player;
public Transform ExitPoint;
public Transform EnterPoint;
PlayerStateMachine playerAttribute;
float distance;
private void Update()
{
if (player)
{
distance = Vector3.Distance(transform.position, player.transform.position);
playerAttribute = player.GetComponent<PlayerStateMachine>();
if (distance < 15)
{
if (playerAttribute.OutsideHouse == false)
{
if (Input.GetKeyDown(KeyCode.E))
{
//Start couroutine to go outside
StartCoroutine(goOutside());
}
}
else if (playerAttribute.OutsideHouse == true)
{
if (Input.GetKeyDown(KeyCode.E))
{
//Start couroutine to go inside
StartCoroutine(goInside());
}
}
}
}
}
IEnumerator goOutside()
{
yield return new WaitForSeconds(1f);
player.transform.position = new Vector3(ExitPoint.position.x, ExitPoint.position.y, ExitPoint.position.z);
}
IEnumerator goInside()
{
yield return new WaitForSeconds(1f);
player.transform.position = new Vector3(EnterPoint.position.x, EnterPoint.position.y, EnterPoint.position.z);
}
When i press E, the player position didn't change to the ExitPoint, it just stuck inside the house