Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class mosq : MonoBehaviour {
- public Sprite alive;
- public Sprite dead;
- bool flying;
- IEnumerator fly;
- // Use this for initialization
- void Start () {
- flying = true;
- fly = MyFunction ();
- StartCoroutine(fly);
- }
- // Update is called once per frame
- void Update () {
- }
- void Began () {
- flying = false;
- StopCoroutine(fly);
- iTween.Stop(gameObject);
- gameObject.GetComponent<SpriteRenderer> ().sprite = dead;
- Destroy (gameObject, 1f);
- }
- IEnumerator MyFunction () {
- Vector3 pos = new Vector3(1f,1f,1f);
- while (flying) {
- yield return new WaitForSeconds (0.8f);
- iTween.Stop(gameObject);
- pos.x = Random.Range (-6.83f,6.83f);
- pos.y = Random.Range (-3.84f,3.84f);
- iTween.MoveTo (transform.gameObject, iTween.Hash ("position", pos, "speed", 10f, "easetype", iTween.EaseType.easeInQuad));
- }
- StopCoroutine(fly);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement