private void OnMouseUpAsButton() { if (rotationable) { dir = rClick.RotateSprite(spriteTF, dir); } }
public DirCompass NextDirection(DirCompass d) { switch (d) { case DirCompass.N: return(DirCompass.NE); case DirCompass.NW: return(DirCompass.N); case DirCompass.W: return(DirCompass.NW); case DirCompass.SW: return(DirCompass.W); case DirCompass.S: return(DirCompass.SW); case DirCompass.SE: return(DirCompass.S); case DirCompass.E: return(DirCompass.SE); case DirCompass.NE: return(DirCompass.E); default: return(DirCompass.N); } }
private void Start() { if (vm == null) { vm = FindObjectOfType <VariablesManager>(); } rClick = GetComponent <RotateSelf>(); if (rClick == null) { rClick = gameObject.AddComponent <RotateSelf>(); } if (spriteTF == null) { spriteTF = GetComponentInChildren <SpriteRenderer>().transform; } dir = rClick.RotateSprite(spriteTF, dir, false); if (startRandom) { dir = vm.GetRandomDir(); rClick.RotateSprite(spriteTF, dir, false); } }
void UpdateSpriteOnDirection(DirCompass dir, SpriteRenderer sr) { switch (dir) { case DirCompass.N: sr.sprite = spriteN; break; case DirCompass.NW: sr.sprite = spriteNW; break; case DirCompass.W: sr.sprite = spriteW; break; case DirCompass.SW: sr.sprite = spriteSW; break; case DirCompass.S: sr.sprite = spriteS; break; case DirCompass.SE: sr.sprite = spriteSE; break; case DirCompass.E: sr.sprite = spriteE; break; case DirCompass.NE: sr.sprite = spriteNE; break; default: break; } }
private void OnMouseUpAsButton() { if (rotationable) { rs = GetComponent <RotateSelf>(); if (rs == null) { rs = gameObject.AddComponent <RotateSelf>(); } dir = rs.RotateSprite(spriteTF, dir); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { dir = collision.GetComponent <MoveForward>().dir; spriteTF.localRotation = Quaternion.Euler(0, 0, (int)dir); V2Int newCratePos = vm.GetTargetCell(new V2Int((int)transform.position.x, (int)transform.position.y), dir); transform.position = new Vector2(newCratePos.x, newCratePos.y); } if ((lethalLayers.value & 1 << collision.gameObject.layer) != 0) { if (collision.CompareTag("Water")) { Destroy(collision.gameObject); } Destroy(gameObject); } }
public V2Int GetTargetCell(V2Int startCell, DirCompass dir) { int px = startCell.x; int py = startCell.y; switch (dir) { case DirCompass.N: py++; break; case DirCompass.NW: px--; py++; break; case DirCompass.W: px--; break; case DirCompass.SW: px--; py--; break; case DirCompass.S: py--; break; case DirCompass.SE: px++; py--; break; case DirCompass.E: px++; break; case DirCompass.NE: px++; py++; break; default: Debug.LogError("Impossible Direction"); break; } return(new V2Int(px, py)); }
public DirCompass RotateSprite(Transform tf, DirCompass dir, bool next = true) { DirCompass newDir = dir; SpriteRenderer spriteR = GetComponentInChildren <SpriteRenderer>(); if (next) { newDir = NextDirection(dir); } if (tf != null) { if (spriteR != null) { tf.localRotation = Quaternion.Euler(0f, 0f, 0f); UpdateSpriteOnDirection(newDir, spriteR); } else { tf.localRotation = Quaternion.Euler(0f, 0f, (float)dir - 45f); } } return(newDir); }