mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-24 11:17:11 +00:00
remove Update()
This commit is contained in:
parent
f0cc7be1e7
commit
b56cad2992
1 changed files with 1 additions and 27 deletions
|
@ -9,10 +9,10 @@ namespace SanAndreasUnity.Behaviours
|
|||
{
|
||||
public float timeUntilDestroyed = 5;
|
||||
public float range = 250;
|
||||
public Transform targetObject = null;
|
||||
|
||||
private float timeSinceOutOfRange = 0;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (NetUtils.IsServer)
|
||||
|
@ -54,31 +54,5 @@ namespace SanAndreasUnity.Behaviours
|
|||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
if (targetObject == null)
|
||||
{
|
||||
if (Camera.main != null)
|
||||
targetObject = Camera.main.transform;
|
||||
}
|
||||
|
||||
if (targetObject != null)
|
||||
{
|
||||
// only increase time if target object exists
|
||||
timeSinceOutOfRange += Time.deltaTime;
|
||||
|
||||
float distanceSq = (transform.position - targetObject.position).sqrMagnitude;
|
||||
if (distanceSq <= range * range)
|
||||
{
|
||||
timeSinceOutOfRange = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (timeSinceOutOfRange >= timeUntilDestroyed)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue