unity switch
public float number;
switch(number)
{
case 1:
Debug.Log("1");
break;
case 2:
Debug.Log("1");
break;
default: //case that happens if no case matches
Debug.Log("I dont know");
break;
}
unity switch
public float number;
switch(number)
{
case 1:
Debug.Log("1");
break;
case 2:
Debug.Log("1");
break;
default: //case that happens if no case matches
Debug.Log("I dont know");
break;
}
change position with Switch unity
// Use this for initialization
void Start ()
{
initialPosition = transform.position;
direction = -1;
maxDist += transform.position.x;
minDist -= transform.position.x;
}
// Update is called once per frame
void Update ()
{
switch (direction)
{
case -1:
// Moving Left
if( transform.position.x > minDist)
{
GetComponent <Rigidbody2D>().velocity = new Vector2(-movingSpeed,GetComponent<Rigidbody2D>().velocity.y);
}
else
{
direction = 1;
}
break;
case 1:
//Moving Right
if(transform.position.x < maxDist)
{
GetComponent <Rigidbody2D>().velocity = new Vector2(movingSpeed,GetComponent<Rigidbody2D>().velocity.y);
}
else
{
direction = -1;
}
break;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us