Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Movement : MonoBehaviour
  6. {
  7.     public float speed = 5.0f;
  8.     public float yspeed = -2.25f;
  9.     public float xspeed = 5;
  10.     public float xrange = 0.5f;
  11.     public bool klicka = false;
  12.     public AudioClip coin;
  13.     private AudioSource hurra;
  14.     private bool playonce = false;
  15.     float time = 0;
  16.     // Start is called before the first frame update
  17.     void Start()
  18.  
  19.     {
  20.         hurra = GetComponent<AudioSource>();
  21.         GetComponent<SpriteRenderer>().enabled = true;
  22.         Debug.Log("starthere");
  23.         //Flugans startposition:
  24.         this.transform.position = new Vector3(0, -3.0f, 0);
  25.     }
  26.     //public void OnCollisionEnter2D(Collision2D collision)
  27.     //{
  28.     //    Debug.Log("hi");
  29.     //    if (collision.gameObject.name == "nostrilleft" || collision.gameObject.name == "nostrilright")
  30.     //    {
  31.     //        Debug.Log("hij");
  32.     //        this.GetComponent<Rigidbody2D>().simulated = false;
  33.            
  34.  
  35.  
  36.     //    }
  37.     //}
  38.  
  39.     private void OnTriggerEnter2D(Collider2D collision)
  40.     {
  41.  
  42.         GameObject.FindObjectOfType<MicroGameFrameworkManager>().EndScene();
  43.         //this.GetComponent<AudioSource>().clip = (namn);
  44.         //this.GetComponent<>
  45.         if (playonce == false)
  46.         {
  47.             Debug.Log("träff");
  48.             hurra.PlayOneShot(coin, 1f);
  49.             playonce = true;
  50.             transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - 20);
  51.             //gör flugan osynlig:
  52.             GetComponent<SpriteRenderer>().enabled = false;
  53.             //byt ut sprite på Background objektet till något disgustedface
  54.         }
  55.        
  56.  
  57.     }
  58.     // Update is called once per frame
  59.     void Update()
  60.     {
  61.         time = time + Time.deltaTime;
  62.        
  63.         //Hur flugan rör sig:
  64.         if (klicka == false)
  65.         {
  66.             //transform.position = new Vector3(xrange * Mathf.Sin(xspeed * Time.time) * speed, -2, 0);
  67.             transform.position = new Vector2(xrange * Mathf.Sin(xspeed * Time.time) * speed, -2);
  68.            
  69.         }
  70.         else
  71.         {
  72.             //transform.position = new Vector3(this.transform.position.x, yspeed += 0.05f, 0);
  73.             transform.position = new Vector2(this.transform.position.x, yspeed += 0.05f);
  74.            
  75.         }
  76.        
  77.  
  78.         //När man klickar:
  79.         if (Input.GetMouseButtonDown(0) && time>0.8)
  80.         {
  81.             klicka = true;
  82.         }
  83.  
  84.      
  85.      
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement