Add player controls and trail
This commit is contained in:
@@ -47,6 +47,6 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public void IncrementScore(int val)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
35
Assets/Scripts/Game/Trail.cs
Normal file
35
Assets/Scripts/Game/Trail.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Trail : MonoBehaviour
|
||||
{
|
||||
public Player player;
|
||||
private ParticleSystem particleSystem;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
particleSystem = GetComponent<ParticleSystem>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnParticleTrigger()
|
||||
{
|
||||
//BUGBUG: This is a hack to get the particles to work.
|
||||
List<ParticleSystem.Particle> insideList = new List<ParticleSystem.Particle>();
|
||||
int numInside = particleSystem.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, insideList);
|
||||
if (numInside > 0)
|
||||
{
|
||||
player.isLit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.isLit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Game/Trail.cs.meta
Normal file
11
Assets/Scripts/Game/Trail.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01382dbef5cd7b3478030187afaadf59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -17,8 +17,10 @@ public class ParticleTest : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnParticleCollision(GameObject other)
|
||||
{
|
||||
Debug.Log(other);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user