Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public float speed = 7f;
- public float attackDelay = 3f;
- public Projectile projectile;
- private Animator animator;
- public AudioClip attackSound;
- void Start () {
- animator = GetComponent<Animator> ();
- if(attackDelay > 0){
- StartCoroutine(onAttack());
- }
- }
- void Update () {
- animator.SetInteger("AnimState", 0);
- }
- IEnumerator onAttack(){
- yield return new WaitForSeconds(attackDelay);
- fire();
- StartCoroutine(onAttack());
- }
- void fire(){
- animator.SetInteger("AnimState", 1);
- if(attackSound){
- AudioSource.PlayClipAtPoint(attackSound, transform.position);
- }
- }
- void onShoot(){
- if (projectile){
- Projectile clone = Instantiate(projectile, transform.position, Quaternion.identity)as Projectile;
- if(transform.localEulerAngles.z == 0){
- clone.rigidbody2D.velocity = new Vector2(0, transform.localScale.y) * speed * -1;
- }
- else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 90){
- clone.rigidbody2D.velocity = new Vector2 (transform.localScale.x, 0) * speed;
- }
- else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 180){
- clone.rigidbody2D.velocity = new Vector2 (0, transform.localScale.y) * speed;
- }
- else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 270){
- clone.rigidbody2D.velocity = new Vector2(transform.localScale.x, 0) * speed * -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement