Created
July 29, 2014 22:51
-
-
Save nastajus/b8326e2fec9f352d22f9 to your computer and use it in GitHub Desktop.
probably lame lane movement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[RequireComponent(typeof(CharacterController))] | |
public class MyController : MonoBehaviour | |
{ | |
enum Lane { left, middle, right }; | |
Lane curLane = Lane.middle; | |
CharacterController cc; | |
void Start () { | |
cc = GetComponent<CharacterController>(); | |
} | |
public void Move(int xDir) | |
{ | |
float MoveDistanceSideways = 2f; | |
float MoveSpeedSideways = 1f; | |
int targetLane = xDir + ((int)curLane - 1); | |
var lanes = System.Enum.GetValues(typeof(Lane)).Cast<Lane>(); | |
foreach (var lane in lanes) | |
{ | |
int iLane = (int)lane - 1; | |
if (iLane == targetLane) | |
{ | |
curLane = (Lane)(targetLane + 1); | |
cc.Move(new Vector3(xDir, 0, 0) * MoveDistanceSideways);// * Time.deltaTime); | |
cc.SimpleMove(Physics.gravity); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment