Good afternoon everybody, I’m working in a script to enable/disable game objectes when they are far from player to increase the FPS. The script is done and have no errors, but he don’t disable/enable the game objects, someone could help me? Thanks a lot.
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Vehicles.Car;
public class DistanceDisabler : MonoBehaviour
{
public GameObject PlayerCar;
public CarController PlayerScript;
public float range = 15;
public GameObject[] ObjectsToDisable;
void Start()
{
PlayerCar = GameObject.FindWithTag("Player");
PlayerScript = PlayerCar.GetComponent<CarController>();
}
void Update()
{
PlayerCar = GameObject.FindWithTag("Player");
PlayerScript = PlayerCar.GetComponent<CarController>();
float distance = Vector3.Distance(PlayerCar.transform.position, transform.position);
{
if (distance >= range)
{
for (int i = 0; i < ObjectsToDisable.Length; i++)
ObjectsToDisable*.SetActive(false);*
-
}*
-
else*
-
if (distance <= range)*
-
{*
-
for (int i = 0; i < ObjectsToDisable.Length; i++)*
_ ObjectsToDisable*.SetActive(true);_
_ }_
_ }_
_}_
_}*_