GUN NO ROTATE :(
This commit is contained in:
@@ -4,6 +4,12 @@ public class GunThrown : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public Vector3 TargetPosition;
|
||||
|
||||
public Vector3 targetDirection;
|
||||
public Quaternion targetRotation;
|
||||
|
||||
public bool isStuck;
|
||||
public float despawnTimer = 10;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
@@ -14,12 +20,28 @@ public class GunThrown : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.LookAt(player.transform);
|
||||
transform.rotation = Quaternion.Euler(transform.rotation.x + 55, transform.rotation.y, transform.rotation.z);
|
||||
transform.position = Vector3.MoveTowards(transform.position, TargetPosition, 10 * Time.deltaTime);
|
||||
|
||||
if (transform.position == TargetPosition)
|
||||
{
|
||||
isStuck = true;
|
||||
}
|
||||
|
||||
if (isStuck)
|
||||
{
|
||||
despawnTimer -= Time.deltaTime;
|
||||
if (despawnTimer <= 0)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
private void OnCollisionStay(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
if (collision.gameObject.tag == "Player" && !isStuck)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ThrowerEnemy : MonoBehaviour
|
||||
playerDistance = Vector3.Distance(transform.position, target.position);
|
||||
if (playerDistance < 25 && canThrow)
|
||||
{
|
||||
Instantiate(GunThrow, transform);
|
||||
Instantiate(GunThrow, transform.position, Quaternion.identity);
|
||||
canThrow = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user