- Home /
Very little, but very heavy script problem.
People, who knows, I have a script and if I attach it to 20 or more objects in the game, when I start the game it is very seriously lagging. I have pretty powerful computer. What is the problem?
// vehicle camera var cam1 : Camera;
// vehicle var vicle : GameObject;
// a place to quit var vihod : Transform;
//player var playerg : GameObject;
function OnTriggerStay (c : Collider)
{if (c.gameObject.Find ("Player").transform)
{if(Input.GetKeyDown(KeyCode.Return))
{cam1.enabled = true;
vicle.GetComponent("Plane").enabled = true;
playerg.active = false;}}}
function Update ()
{if (cam1.enabled == true)
{if(Input.GetKeyDown(KeyCode.Backspace))
{playerg.active = true;
GameObject.Find ("Player").transform.position = vihod.position;
cam1.enabled = false;
vicle.GetComponent("Plane").enabled = false;}}}
Step 1 : read this page : http://answers.unity3d.com/page/newuser.html
Step 2 : Format your code
For any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
What did you do to get such a low karma rating? $$anonymous$$y guess is posting comments as answers.
I gave the benefit of the doubt and approved this question.
Your problem lies in the way you are using GameObject.Find ("Player") and GetComponent("Plane") . You should only be doing this once on Start/Enable . Store those references and use those references in the rest of your script. eg :
var playerTransform : Transform
function Start()
{
playerTransform = GameObject.Find ("Player").transform;
}
function Update()
{
//
playerTransform.position = vihod.position;
//
}
This line I don't understand :
function OnTriggerStay (c : Collider)
{
if (c.gameObject.Find ("Player").transform)
do you mean
if (c.transform == playerTransform )
Your answer
Follow this Question
Related Questions
Stopping a function when another function running. 2 Answers
C# Scripts don't work in Unity 3.5 any idea why? 1 Answer
A node in a childnode? 1 Answer
What is missing from Unity Pro in the Unity Free edition 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers