Hi there. I have the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player1CharacterController : MonoBehaviour
{
public Transform P2;
void Update()
{
if (transform.position.x <= P2.position.x)
{
facingleft = 0;
}
if (transform.position.x >= P2.position.x)
{
facingleft = 1;
}
if (facingleft == 0)
{
transform.localScale = Vector3.Scale(transform.localScale, new Vector3(1, 1, 1));
}
if (facingleft == 1)
{
transform.localScale = Vector3.Scale(transform.localScale, new Vector3(-1, 1, 1));
}
}
}
When the object crosses onto the other side of P2, the x scale should change to -1. However, when the object cross to the other side, it’s scale keeps flipping from -1 to 1. This makes me think the script is repeatedly multiplying the x-scale by -1, rather than just multiplying it once when the object moves over. I have looked at and tried to understand about 8 different threads now, as well as looking at the unity manual, and I am still stumped. Any help is appreciated.
Thank you,
Victor