mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-02-17 12:28:10 +01:00
fix: jump issues (#36)
This commit is contained in:
parent
c6be884024
commit
af64c2e0f4
@ -5,44 +5,40 @@ public class PlayerScript : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public Rigidbody2D rigidBody;
|
public Rigidbody2D rigidBody;
|
||||||
public GameObject playerObject;
|
public GameObject playerObject;
|
||||||
|
|
||||||
public ParticleSystem particle;
|
public ParticleSystem particle;
|
||||||
|
|
||||||
private bool wantsToJump = false;
|
|
||||||
public bool isColliding = true;
|
public bool isColliding = true;
|
||||||
|
|
||||||
public AudioSource audioSource;
|
public AudioSource audioSource;
|
||||||
|
private bool hasStarted = false;
|
||||||
|
|
||||||
|
private bool canJump = true;
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
var mainModule = particle.main;
|
var mainModule = particle.main;
|
||||||
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
|
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||||
particle.transform.parent = null;
|
particle.transform.parent = null;
|
||||||
|
|
||||||
|
Invoke(nameof(EnableInput), 0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EnableInput()
|
||||||
|
{
|
||||||
|
hasStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
transform.position += Time.deltaTime * 8.6f * Vector3.right;
|
rigidBody.linearVelocity = new Vector2(8.6f, rigidBody.linearVelocity.y);
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.Space))
|
if (hasStarted && isColliding && Input.GetKey(KeyCode.Space) && canJump)
|
||||||
{
|
{
|
||||||
wantsToJump = true;
|
Jump();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wantsToJump = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsJumping())
|
if (!IsJumping())
|
||||||
{
|
{
|
||||||
AlignRotation();
|
AlignRotation();
|
||||||
|
|
||||||
if (wantsToJump)
|
|
||||||
{
|
|
||||||
Jump();
|
|
||||||
wantsToJump = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
particle.gameObject.SetActive(true);
|
particle.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -88,13 +84,14 @@ public class PlayerScript : MonoBehaviour
|
|||||||
public void OnCollisionEnter2D(Collision2D collision)
|
public void OnCollisionEnter2D(Collision2D collision)
|
||||||
{
|
{
|
||||||
isColliding = true;
|
isColliding = true;
|
||||||
|
canJump = true;
|
||||||
|
|
||||||
if (collision.gameObject.tag == "Kill")
|
if (collision.gameObject.CompareTag("Kill"))
|
||||||
{
|
{
|
||||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collision.gameObject.tag == "Win")
|
if (collision.gameObject.CompareTag("Win"))
|
||||||
{
|
{
|
||||||
SceneManager.LoadScene("HomeScene");
|
SceneManager.LoadScene("HomeScene");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user