I have a camera movement script but I don’t know how to put a box down that will make a border in script.
|
public float rotationSpeed;
public float movementSpeed;
public bool movementType;
void Update()
{
if(movementType == false)
{
transform.Rotate(0f, Input.GetAxis("Horizontal") * rotationSpeed, 0f);
}
else
{
transform.Translate(Input.GetAxis("Horizontal") * movementSpeed, 0f, 0f);
}
transform.Translate( 0f, 0f, Input.GetAxis("Vertical") * movementSpeed);
}
just set some coordinates for boundrys and just check some if statements for your box
public float rotationSpeed;
public float movementSpeed;
public bool movementType;
public float n,s,e,w;
void Update() {
float f;
if(movementType == false) {
transform.Rotate(0f, Input.GetAxis("Horizontal") * rotationSpeed, 0f); } else {
f = Input.GetAxis("Horizontal") ;
if(f>0&&transform.position.x>e){f=0;}
if(f<0&&transform.position.x<w){f=0;}
transform.Translate(f* movementSpeed, 0f, 0f);
}
f = Input.GetAxis("Vertical") ;
if(f>0&&transform.position.z>n){f=0;}
if(f<0&&transform.position.z<s){f=0;}
transform.Translate( 0f, 0f,f* movementSpeed);
}