Guest User

Untitled

a guest
Oct 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityStandardAssets.CrossPlatformInput;
  6. using UnityEngine.EventSystems;
  7.  
  8. public class Frog : MonoBehaviour {
  9.  
  10. public AudioClip MusicClip;
  11.  
  12. float directionX;
  13.  
  14. private AudioSource MusicSource;
  15.  
  16. private Scene scene;
  17.  
  18. private Rigidbody2D myBody;
  19.  
  20. void Awake()
  21. {
  22. myBody = GetComponent<Rigidbody2D>();
  23. MusicSource = GetComponent<AudioSource>();
  24. }
  25.  
  26. private void Update() {
  27.  
  28. directionX = CrossPlatformInputManager.GetAxis("Horizontal");
  29. myBody.velocity = new Vector2(directionX * 8, 0);
  30.  
  31. if (!EventSystem.current.IsPointerOverGameObject(-1))
  32. {
  33. if (Input.GetMouseButtonDown(0))
  34. myBody.MovePosition(myBody.position + Vector2.up);
  35. }
  36. } //update
  37.  
  38. void Start()
  39. {
  40. scene = SceneManager.GetActiveScene();
  41. MusicSource.clip = MusicClip;
  42.  
  43. }
  44.  
  45. void OnTriggerEnter2D(Collider2D target)
  46. {
  47.  
  48. if (target.tag == "Car")
  49. {
  50. Application.LoadLevel(scene.name);
  51. }
  52.  
  53. if (target.tag == "Car")
  54. {
  55. MusicSource.Play();
  56. }
  57. }
  58.  
  59. } //class
Advertisement
Add Comment
Please, Sign In to add comment