Advertisement
Guest User

mosq

a guest
Nov 29th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class mosq : MonoBehaviour {
  5.  
  6. public Sprite alive;
  7. public Sprite dead;
  8.  
  9. bool flying;
  10. IEnumerator fly;
  11. // Use this for initialization
  12. void Start () {
  13. flying = true;
  14. fly = MyFunction ();
  15. StartCoroutine(fly);
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update () {
  20.  
  21. }
  22.  
  23. void Began () {
  24. flying = false;
  25. StopCoroutine(fly);
  26. iTween.Stop(gameObject);
  27. gameObject.GetComponent<SpriteRenderer> ().sprite = dead;
  28. Destroy (gameObject, 1f);
  29. }
  30.  
  31. IEnumerator MyFunction () {
  32. Vector3 pos = new Vector3(1f,1f,1f);
  33. while (flying) {
  34. yield return new WaitForSeconds (0.8f);
  35. iTween.Stop(gameObject);
  36. pos.x = Random.Range (-6.83f,6.83f);
  37. pos.y = Random.Range (-3.84f,3.84f);
  38. iTween.MoveTo (transform.gameObject, iTween.Hash ("position", pos, "speed", 10f, "easetype", iTween.EaseType.easeInQuad));
  39. }
  40. StopCoroutine(fly);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement