mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-27 11:58:51 +02:00
feat: place cube and jump + move camera (#24)
This commit is contained in:
12
Assets/Scripts/CameraScript.cs
Normal file
12
Assets/Scripts/CameraScript.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraScript : MonoBehaviour
|
||||
{
|
||||
public GameObject playerObject;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
transform.position = new Vector3(playerObject.transform.position.x, transform.position.y, transform.position.z);
|
||||
// transform.position = new Vector3(player.transform.position.x, player.transform.position.y, transform.position.z);
|
||||
}
|
||||
}
|
2
Assets/Scripts/CameraScript.cs.meta
Normal file
2
Assets/Scripts/CameraScript.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d5072680bac39145a7c5d603b1ab715
|
32
Assets/Scripts/PlayerScript.cs
Normal file
32
Assets/Scripts/PlayerScript.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerScript : MonoBehaviour
|
||||
{
|
||||
public Rigidbody2D rigidBody;
|
||||
public GameObject groundObject;
|
||||
|
||||
public Vector3 initialPosition;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
initialPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
transform.position += Time.deltaTime * 8.6f * Vector3.right;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
if (!IsJumping())
|
||||
{
|
||||
rigidBody.AddForce(Vector2.up * 26.6581f, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsJumping()
|
||||
{
|
||||
return Mathf.Abs(initialPosition.y - transform.position.y) > 0.05f;
|
||||
}
|
||||
}
|
2
Assets/Scripts/PlayerScript.cs.meta
Normal file
2
Assets/Scripts/PlayerScript.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebe0bd74200510d4aa75c327a76499c6
|
Reference in New Issue
Block a user