Hi guys,
I’m an artist who is using Unity (love it) and familiarizing myself with C#. I’m pretty new to scripting, but here’s my situation:
I have a Starfox style type shooter, with a ship attached to a GameObject that travels forward (Z Axis) at constant rate. Currently, that ship can move freely in the X/Y, but I want to limit the amount that it can move in the X/Y so it doesn’t go off the camera view.
Here’s my code:
void Update ()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(Input.GetAxis ("Horizontal"),invert*Input.GetAxis("Vertical"),0);
Vector3 finalDirection = new Vector3(horizontal,invert*vertical,5.0f);
transform.position += direction*bankMultiply*movementSpeed*Time.deltaTime;
Vector3 boundaryVector = transform.position;
//Testing Boundaries
if(boundaryVector.x < -4.5f)
{
boundaryVector.x += -4.5f;
}
With this test, nothing changed. I was still able to fly past -4.5 on the X axis. Any ideas?
Thanks!