Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movement : MonoBehaviour
- {
- public float speed = 5.0f;
- public float yspeed = -2.25f;
- public float xspeed = 5;
- public float xrange = 0.5f;
- public bool klicka = false;
- public AudioClip coin;
- private AudioSource hurra;
- private bool playonce = false;
- float time = 0;
- // Start is called before the first frame update
- void Start()
- {
- hurra = GetComponent<AudioSource>();
- GetComponent<SpriteRenderer>().enabled = true;
- Debug.Log("starthere");
- //Flugans startposition:
- this.transform.position = new Vector3(0, -3.0f, 0);
- }
- //public void OnCollisionEnter2D(Collision2D collision)
- //{
- // Debug.Log("hi");
- // if (collision.gameObject.name == "nostrilleft" || collision.gameObject.name == "nostrilright")
- // {
- // Debug.Log("hij");
- // this.GetComponent<Rigidbody2D>().simulated = false;
- // }
- //}
- private void OnTriggerEnter2D(Collider2D collision)
- {
- GameObject.FindObjectOfType<MicroGameFrameworkManager>().EndScene();
- //this.GetComponent<AudioSource>().clip = (namn);
- //this.GetComponent<>
- if (playonce == false)
- {
- Debug.Log("träff");
- hurra.PlayOneShot(coin, 1f);
- playonce = true;
- transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - 20);
- //gör flugan osynlig:
- GetComponent<SpriteRenderer>().enabled = false;
- //byt ut sprite på Background objektet till något disgustedface
- }
- }
- // Update is called once per frame
- void Update()
- {
- time = time + Time.deltaTime;
- //Hur flugan rör sig:
- if (klicka == false)
- {
- //transform.position = new Vector3(xrange * Mathf.Sin(xspeed * Time.time) * speed, -2, 0);
- transform.position = new Vector2(xrange * Mathf.Sin(xspeed * Time.time) * speed, -2);
- }
- else
- {
- //transform.position = new Vector3(this.transform.position.x, yspeed += 0.05f, 0);
- transform.position = new Vector2(this.transform.position.x, yspeed += 0.05f);
- }
- //När man klickar:
- if (Input.GetMouseButtonDown(0) && time>0.8)
- {
- klicka = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement