// Use this for initialization void Start() { // brown team starts at the top of the screen and moves down if (myStats.teamName == "brown") { dir_y = -1.0f; prevDir = mv_dir.s; if (animator) { animator.SetTrigger("face s"); } } }
public int courseStay = 0; // prevent reversing dir after wall hit just reversed dir void checkForDirChange() { if (!animator) { return; } mv_dir currDir; bool north = false, south = false, east = false, west = false; // normalize to larger if (Mathf.Abs(dir_x) > Mathf.Abs(dir_y)) { // no divide by zero if (dir_x == 0.0f) { dir_x = 0.1f; } dir_x = dir_x / Mathf.Abs(dir_x); dir_y = dir_y / Mathf.Abs(dir_x); } else { // no divide by zero if (dir_y == 0.0f) { dir_y = 0.1f; } dir_x = dir_x / Mathf.Abs(dir_y); dir_y = dir_y / Mathf.Abs(dir_y); } if (dir_x > 0.5f) { east = true; } else if (dir_x < -0.5f) { west = true; } if (dir_y > 0.5f) { north = true; } else if (dir_y < -0.5f) { south = true; } if (east) { if (south) { currDir = mv_dir.se; } else if (north) { currDir = mv_dir.ne; } else { currDir = mv_dir.e; } } else if (west) { if (south) { currDir = mv_dir.sw; } else if (north) { currDir = mv_dir.nw; } else { currDir = mv_dir.w; } } else if (north) { currDir = mv_dir.n; } else { currDir = mv_dir.s; } if (currDir != prevDir) { prevDir = currDir; switch (currDir) { case mv_dir.n: animator.SetTrigger("face n"); break; case mv_dir.ne: animator.SetTrigger("face ne"); break; case mv_dir.e: animator.SetTrigger("face e"); break; case mv_dir.se: animator.SetTrigger("face se"); break; case mv_dir.s: animator.SetTrigger("face s"); break; case mv_dir.sw: animator.SetTrigger("face sw"); break; case mv_dir.w: animator.SetTrigger("face w"); break; case mv_dir.nw: animator.SetTrigger("face nw"); break; } } }