Hello guys,
Well I’m making a game and it’s all going well at the start, but after a while the game looses a lot of fps, and the inspector says that this scrypt is one of the “bad guys”, so after some research and many fixing attempts I’m here asking for some advice of you… Here’s my scrypt, its actualy simple but for some reason this “bad boy” is eating alot of resouces.
using UnityEngine;
using System.Collections;
public class Faller : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
Game_Controller Controller = GameObject.FindObjectOfType<Game_Controller>();
if (Controller.Has_Placed && Controller.IsEating == false || Controller.Has_Placed2 && Controller.IsEating == false)
{
CastIT();
}
}
void CastIT()
{
RaycastHit hit;
Physics.Raycast(transform.position, Vector3.back, out hit;
if (hit.distance >= 0.5f)
{
float New_Distance = hit.distance - 0.5f;
transform.position = new Vector3(transform.position.x, 0, transform.position.z - New_Distance);
}
}
}
I hope someone can give me some advice