This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Game 1/Assets/Scripts/PlayerController.cs

43 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
// Simple script for a test I need to do
public class PlayerController : MonoBehaviour {
public float jumpPower;
2017-09-04 16:39:17 -05:00
public AnimationClip explosion;
private AnimationClip explode;
// Use this for initialization
void Start () {
2017-09-04 16:39:17 -05:00
explode = (AnimationClip)Instantiate(explosion, Camera.main.ScreenToWorldPoint(Input.mousePosition), Quaternion.identity);
}
// Update is called once per frame
void Update () {
2017-09-04 16:39:17 -05:00
// Basic jumping
if (Input.GetKeyDown (KeyCode.Space)) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, jumpPower);
}
2017-09-04 16:39:17 -05:00
if (Input.GetMouseButtonDown(0))
{
//explode.Play();
2017-09-04 16:39:17 -05:00
Debug.Log("Explosion at: " + Input.mousePosition);
}
}
// Handle collisions with Deathbox to trigger level restart.
void OnTriggerEnter2D(Collider2D other) {
// Deathbox and saws restart level
if (other.gameObject.name == "Deathbox" || other.gameObject.name == "Saw") {
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}