Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityStandardAssets.CrossPlatformInput;
- using UnityEngine.EventSystems;
- public class Frog : MonoBehaviour {
- public AudioClip MusicClip;
- float directionX;
- private AudioSource MusicSource;
- private Scene scene;
- private Rigidbody2D myBody;
- void Awake()
- {
- myBody = GetComponent<Rigidbody2D>();
- MusicSource = GetComponent<AudioSource>();
- }
- private void Update() {
- directionX = CrossPlatformInputManager.GetAxis("Horizontal");
- myBody.velocity = new Vector2(directionX * 8, 0);
- if (!EventSystem.current.IsPointerOverGameObject(-1))
- {
- if (Input.GetMouseButtonDown(0))
- myBody.MovePosition(myBody.position + Vector2.up);
- }
- } //update
- void Start()
- {
- scene = SceneManager.GetActiveScene();
- MusicSource.clip = MusicClip;
- }
- void OnTriggerEnter2D(Collider2D target)
- {
- if (target.tag == "Car")
- {
- Application.LoadLevel(scene.name);
- }
- if (target.tag == "Car")
- {
- MusicSource.Play();
- }
- }
- } //class
Advertisement
Add Comment
Please, Sign In to add comment