mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-10 22:20:40 +02:00
feat: collision with a spike (#28)
This commit is contained in:
@ -2,20 +2,22 @@ using UnityEngine;
|
||||
|
||||
public class Obstacle : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
public PlayerScript playerScript;
|
||||
public GameObject playerObject;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerScript>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
Debug.Log("Test");
|
||||
playerObject.transform.rotation = playerScript.initialRotation;
|
||||
playerObject.transform.position = playerScript.initialPosition;
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,21 @@ public class PlayerScript : MonoBehaviour
|
||||
public GameObject groundObject;
|
||||
|
||||
public Vector3 initialPosition;
|
||||
public Quaternion initialRotation;
|
||||
|
||||
public ParticleSystem particleSystem;
|
||||
public ParticleSystem particle;
|
||||
|
||||
private bool wantsToJump = false;
|
||||
private bool isGrounded = true;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
initialPosition = transform.position;
|
||||
initialRotation = transform.rotation;
|
||||
|
||||
var mainModule = particleSystem.main;
|
||||
var mainModule = particle.main;
|
||||
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
|
||||
particleSystem.transform.parent = null;
|
||||
particle.transform.parent = null;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@ -37,7 +38,6 @@ public class PlayerScript : MonoBehaviour
|
||||
|
||||
if (!IsJumping())
|
||||
{
|
||||
isGrounded = true;
|
||||
AlignRotation();
|
||||
|
||||
if (wantsToJump)
|
||||
@ -46,12 +46,11 @@ public class PlayerScript : MonoBehaviour
|
||||
wantsToJump = false;
|
||||
}
|
||||
|
||||
particleSystem.gameObject.SetActive(true);
|
||||
particle.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
isGrounded = false;
|
||||
particleSystem.gameObject.SetActive(false);
|
||||
particle.gameObject.SetActive(false);
|
||||
transform.Rotate(Vector3.back * 360 * Time.deltaTime);
|
||||
}
|
||||
|
||||
@ -79,13 +78,13 @@ public class PlayerScript : MonoBehaviour
|
||||
|
||||
private void UpdateParticlePositionAndRotation()
|
||||
{
|
||||
particleSystem.transform.position = transform.position + new Vector3(-0.19f, -0.64f, 0);
|
||||
particleSystem.transform.rotation = Quaternion.Euler(0, 0, 150.464f);
|
||||
particle.transform.position = transform.position + new Vector3(-0.19f, -0.64f, 0);
|
||||
particle.transform.rotation = Quaternion.Euler(0, 0, 150.464f);
|
||||
}
|
||||
|
||||
private void UpdateParticleSystemSpeed()
|
||||
{
|
||||
var velocityOverLifetime = particleSystem.velocityOverLifetime;
|
||||
var velocityOverLifetime = particle.velocityOverLifetime;
|
||||
velocityOverLifetime.x = rigidBody.linearVelocity.x;
|
||||
}
|
||||
}
|
||||
|
23
Assets/Scripts/SpikeScript.cs
Normal file
23
Assets/Scripts/SpikeScript.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SpikeScript : MonoBehaviour
|
||||
{
|
||||
public PlayerScript playerScript;
|
||||
public GameObject playerObject;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerScript>();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
playerObject.transform.rotation = playerScript.initialRotation;
|
||||
playerObject.transform.position = playerScript.initialPosition;
|
||||
}
|
||||
}
|
2
Assets/Scripts/SpikeScript.cs.meta
Normal file
2
Assets/Scripts/SpikeScript.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b6c5b0fa69a1f00da3d8c4aa96485f3
|
Reference in New Issue
Block a user