GUN GETS THROWN
This commit is contained in:
27
Assets/Scripts/GunThrown.cs
Normal file
27
Assets/Scripts/GunThrown.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GunThrown : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public Vector3 TargetPosition;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.Find("Player");
|
||||
TargetPosition = player.transform.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.position = Vector3.MoveTowards(transform.position, TargetPosition, 10 * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/GunThrown.cs.meta
Normal file
2
Assets/Scripts/GunThrown.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe870c030a2b648d89c63559e7522299
|
||||
@@ -11,7 +11,7 @@ public class ThrowerEnemy : MonoBehaviour
|
||||
public bool isInside;
|
||||
|
||||
public float playerDistance;
|
||||
public GameObject GunBayonette;
|
||||
public GameObject GunThrow;
|
||||
|
||||
private NavMeshAgent agent;
|
||||
public Transform target;
|
||||
@@ -42,7 +42,7 @@ public class ThrowerEnemy : MonoBehaviour
|
||||
playerDistance = Vector3.Distance(transform.position, target.position);
|
||||
if (playerDistance < 25)
|
||||
{
|
||||
Instantiate(GunBayonette);
|
||||
Instantiate(GunThrow, transform);
|
||||
}
|
||||
}
|
||||
private void LateUpdate()
|
||||
|
||||
Reference in New Issue
Block a user