Add player controls and trail

This commit is contained in:
2022-04-17 21:57:09 +02:00
parent 4e4bd27bbc
commit 1bd6d79672
17 changed files with 5446 additions and 19 deletions

View File

@@ -1,24 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
public int health;
public float health;
public float speed;
public float trailLength;
public ParticleSystem trail;
public GameObject trail;
public float rotationSpeed;
public float direction;
public List<ParticleCollisionEvent> collisionEvents;
public bool isLit;
public Camera camera;
// Start is called before the first frame update
void Start()
{
collisionEvents = new List<ParticleCollisionEvent>();
}
public void OnMove(InputValue value)
{
Vector2 inputVector = value.Get<Vector2>();
direction = inputVector.x;
}
// Update is called once per frame
void Update()
{
//if isLit decrease health
if (isLit)
{
health -= 100.0f * Time.deltaTime;
Debug.Log("Health: " + health);
}
//move player forward
transform.position += transform.forward * speed * Time.deltaTime;
//rotate based on direction
transform.Rotate(0, direction * rotationSpeed * 2 * Time.deltaTime, 0);
float horzExtent = camera.orthographicSize * Screen.width / Screen.height;
float vertExtent = camera.orthographicSize;
if (transform.position.z > vertExtent)
{
transform.position = new Vector3(transform.position.x, transform.position.y, -vertExtent);
}
else if (transform.position.z < -vertExtent)
{
transform.position = new Vector3(transform.position.x, transform.position.y, vertExtent);
}
if (transform.position.x > horzExtent)
{
transform.position = new Vector3(-horzExtent, transform.position.y, transform.position.z);
}
else if (transform.position.x < -horzExtent)
{
transform.position = new Vector3(horzExtent, transform.position.y, transform.position.z);
}
}
public void DecreaseTrail(float val)
@@ -31,11 +80,12 @@ public class Player : MonoBehaviour
//Increate trail length
}
private void OnParticleCollision(GameObject other)
{
if (other == trail)
{
//Hit by trail
//Debug.Log(other.name);
}
}
}