Polishing the sprites

This commit is contained in:
2018-04-22 23:36:11 +10:00
parent c25705bd01
commit c6b700f51e
35 changed files with 1643 additions and 5 deletions
+47
View File
@@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cannon : MonoBehaviour {
SpriteRenderer spriteRenderer;
public enum Direction {
NORTH, EAST, SOUTH, WEST
};
public Direction direction;
public GameObject pelletPrefab;
public float delay;
float speed = 3f;
public Sprite sprite; //TMP, hopefully
void Awake() {
spriteRenderer = GetComponent<SpriteRenderer> ();
spriteRenderer.sprite = sprite;
StartCoroutine (FireOnTimer (delay));
}
IEnumerator FireOnTimer(float seconds) {
while(true) {
yield return new WaitForSeconds (seconds);
GameObject go = Instantiate (pelletPrefab);
go.transform.position = transform.position;
switch (direction) {
case Direction.NORTH:
go.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, speed), ForceMode2D.Impulse);
break;
case Direction.EAST:
go.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (speed, 0), ForceMode2D.Impulse);
break;
case Direction.SOUTH:
go.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, -speed), ForceMode2D.Impulse);
break;
case Direction.WEST:
go.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (-speed, 0), ForceMode2D.Impulse);
break;
}
}
}
}