Added checkpoints
This commit is contained in:
@@ -4,6 +4,10 @@ using UnityEngine.Events;
|
||||
public class CharacterController2D : MonoBehaviour
|
||||
{
|
||||
public float m_JumpForce = 400f; // Amount of force added when the player jumps.
|
||||
|
||||
public AudioSource SFX;
|
||||
public AudioClip JumpSFX;
|
||||
|
||||
[Range(0, .3f)] [SerializeField] private float m_MovementSmoothing = .05f; // How much to smooth out the movement
|
||||
[SerializeField] private bool m_AirControl = false; // Whether or not a player can steer while jumping;
|
||||
[SerializeField] private LayerMask m_WhatIsGround; // A mask determining what is ground to the character
|
||||
@@ -83,6 +87,8 @@ public class CharacterController2D : MonoBehaviour
|
||||
// Add a vertical force to the player.
|
||||
m_Grounded = false;
|
||||
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
|
||||
SFX.clip = JumpSFX;
|
||||
SFX.Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
35
Assets/Scripts/Checkpoint.cs
Normal file
35
Assets/Scripts/Checkpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Checkpoint : MonoBehaviour
|
||||
{
|
||||
public AudioClip checkpoint;
|
||||
public SpawnStorage spawnstor;
|
||||
public AudioSource sfx;
|
||||
|
||||
public Sprite Green;
|
||||
public CircleCollider2D circ;
|
||||
public SpriteRenderer sprite;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
private void OnCollisionEnter2D (Collision2D collisionInfo)
|
||||
{
|
||||
if (collisionInfo.collider.name == "Player") {
|
||||
circ.enabled = false;
|
||||
sprite.sprite = Green;
|
||||
spawnstor.spawnpoint = transform.position;
|
||||
sfx.clip = checkpoint;
|
||||
sfx.Play();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Checkpoint.cs.meta
Normal file
11
Assets/Scripts/Checkpoint.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43836a9c51ff19640b207077aac47076
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -6,13 +6,20 @@ using UnityEngine;
|
||||
public class Death : MonoBehaviour
|
||||
{
|
||||
|
||||
public SpawnStorage spawnstor;
|
||||
public AudioClip damage;
|
||||
|
||||
public AudioSource sfx;
|
||||
|
||||
void Start() {
|
||||
}
|
||||
private void OnCollisionEnter2D (Collision2D collisionInfo)
|
||||
{
|
||||
if (collisionInfo.collider.name == "Player") {
|
||||
collisionInfo.collider.transform.position = Vector3.zero;
|
||||
collisionInfo.collider.transform.position = spawnstor.spawnpoint;
|
||||
collisionInfo.collider.GetComponent<Rigidbody2D>().velocity = Vector3.zero;
|
||||
sfx.clip = damage;
|
||||
sfx.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,10 +6,13 @@ public class PlayerControls : MonoBehaviour
|
||||
{
|
||||
public Animator animator;
|
||||
public PhysicsMaterial2D top;
|
||||
public Rigidbody2D rigidbody;
|
||||
public Rigidbody2D rb;
|
||||
public AudioClip RotateSFX;
|
||||
|
||||
public SpriteRenderer sprite;
|
||||
public PhysicsMaterial2D bottom;
|
||||
public CharacterController2D controller;
|
||||
public AudioSource sfx;
|
||||
public float runspeed = 40f;
|
||||
float horizonatalaxis = 0f;
|
||||
|
||||
@@ -33,14 +36,16 @@ public class PlayerControls : MonoBehaviour
|
||||
switchy = !switchy;
|
||||
if (switchy){
|
||||
sprite.flipY = true;
|
||||
rigidbody.sharedMaterial = top;
|
||||
rb.sharedMaterial = top;
|
||||
controller.m_JumpForce = controller.m_JumpForce * 1.2f;
|
||||
}
|
||||
else {
|
||||
sprite.flipY = false;
|
||||
rigidbody.sharedMaterial = bottom;
|
||||
rb.sharedMaterial = bottom;
|
||||
controller.m_JumpForce = controller.m_JumpForce * 0.8f;
|
||||
}
|
||||
sfx.clip = RotateSFX;
|
||||
sfx.Play();
|
||||
}
|
||||
|
||||
|
||||
|
15
Assets/Scripts/SpawnStorage.cs
Normal file
15
Assets/Scripts/SpawnStorage.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpawnStorage : MonoBehaviour
|
||||
{
|
||||
|
||||
// Start is called before the first frame update
|
||||
public Vector3 spawnpoint;
|
||||
void Start()
|
||||
{
|
||||
spawnpoint = transform.position;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/SpawnStorage.cs.meta
Normal file
11
Assets/Scripts/SpawnStorage.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8dcd45aad7617f43bc9b5ef48ebf485
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user