GUNS GUNS GUNS
GUESS WHAT
This commit is contained in:
parent
1e273d691e
commit
8aaccac2b5
83 changed files with 15291 additions and 1291 deletions
62
Assets/Projectile.cs
Normal file
62
Assets/Projectile.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using UnityEngine;
|
||||
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
public TrailRenderer Trail;
|
||||
public float Gravity;
|
||||
|
||||
private bool _alive;
|
||||
public Zone Zone { get; set; }
|
||||
|
||||
public Vector3 Velocity { get; set; }
|
||||
public float Damage { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_alive = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (SourceEntity == null) return;
|
||||
|
||||
var position = transform.position;
|
||||
Velocity += Vector3.up * (sign(Zone.GetHeight(float2(position.x,position.z)) - position.y) * Gravity * Time.deltaTime);
|
||||
var ray = new Ray(position, Velocity);
|
||||
if (Physics.Raycast(ray, out var hit, Velocity.magnitude, LayerMask.NameToLayer("Combat")))
|
||||
{
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
hull.SendHit(Damage, DamageType, SourceEntity, hit);
|
||||
}
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
if(_alive)
|
||||
transform.position += Velocity;
|
||||
}
|
||||
|
||||
IEnumerator Kill()
|
||||
{
|
||||
_alive = false;
|
||||
var startTime = Time.time;
|
||||
var lifetime = Trail.time;
|
||||
while (Time.time - startTime < lifetime)
|
||||
yield return null;
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue