Hello,
I just created this very basic scripts that lets a cube spawn into a different location in the opposite side whenever it reaches a certain location, it’s working fine, the problem I’m facing is that I wanted to do the same thing for a different object but the behavior should be mirrored for the opposite side, i tried using the same original script i created with updated names and locations to match the new object but it doesn’t work
Any idea why this is not working guys? Any help or guidance will be much appreciated,I’m a 3d artist and this is my first attempt into coding in unity
Thank you so much for ready and your time
Here is the original script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class leftdirection : MonoBehaviour {
public float sidewayspeed = 10f;
public Transform player;
public Vector3 leftlimit ;
public Vector3 rightlimit;
void Start()
{
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey(“left”))
gameObject.transform.Translate(-sidewayspeed * Time.deltaTime, 0, 0);
if (transform.position == leftlimit)
transform.position = rightlimit;
}
}
and this is the mirrored script that is not working :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rightdirection : MonoBehaviour {
public float sidewayspeed = 10f;
public Transform player;
public Vector3 leftlimit ;
public Vector3 rightlimit;
void Start()
{
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey(“right”))
gameObject.transform.Translate(sidewayspeed * Time.deltaTime, 0, 0);
if (transform.position == rightlimit)
transform.position = leftlimit;
}
}