Working on lession 29
This commit is contained in:
38
Assets/Scripts/Towers/Projectile.cs
Normal file
38
Assets/Scripts/Towers/Projectile.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
private Rigidbody theRB;
|
||||
[SerializeField] private float moveSpeed;
|
||||
[SerializeField] private float damageAmount;
|
||||
[SerializeField] private GameObject impactEffect;
|
||||
void Awake()
|
||||
{
|
||||
theRB = GetComponent<Rigidbody>();
|
||||
}
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
theRB.linearVelocity = transform.forward * moveSpeed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.tag == "Enemy")
|
||||
{
|
||||
other.GetComponent<EnemyHealthController>().TakeDamage(damageAmount);
|
||||
Instantiate(impactEffect, transform.position, transform.rotation);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
void OnBecameVisible()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user