Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public float speed = 7f;
  2. public float attackDelay = 3f;
  3. public Projectile projectile;
  4.  
  5. private Animator animator;
  6.  
  7. public AudioClip attackSound;
  8.  
  9. void Start () {
  10. animator = GetComponent<Animator> ();
  11.  
  12. if(attackDelay > 0){
  13.  
  14. StartCoroutine(onAttack());
  15. }
  16. }
  17.  
  18. void Update () {
  19. animator.SetInteger("AnimState", 0);
  20. }
  21.  
  22. IEnumerator onAttack(){
  23. yield return new WaitForSeconds(attackDelay);
  24. fire();
  25. StartCoroutine(onAttack());
  26. }
  27.  
  28. void fire(){
  29. animator.SetInteger("AnimState", 1);
  30.  
  31. if(attackSound){
  32. AudioSource.PlayClipAtPoint(attackSound, transform.position);
  33. }
  34. }
  35. void onShoot(){
  36. if (projectile){
  37. Projectile clone = Instantiate(projectile, transform.position, Quaternion.identity)as Projectile;
  38. if(transform.localEulerAngles.z == 0){
  39. clone.rigidbody2D.velocity = new Vector2(0, transform.localScale.y) * speed * -1;
  40. }
  41. else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 90){
  42.  
  43. clone.rigidbody2D.velocity = new Vector2 (transform.localScale.x, 0) * speed;
  44. }
  45. else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 180){
  46. clone.rigidbody2D.velocity = new Vector2 (0, transform.localScale.y) * speed;
  47. }
  48. else if(Mathf.RoundToInt(transform.localEulerAngles.z) == 270){
  49. clone.rigidbody2D.velocity = new Vector2(transform.localScale.x, 0) * speed * -1;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement