- Home /
Scripting performance questions (JS)
I have couple of questions, about which one is faster for calculation, from tne Engine, when the game gets build.
1 - I have watched several tutorials, where the programmer is making one script for the movement, another script for the fire, another script for the collision... So which one is faster 1 Script for all the stuff, that have to do with the player (for example) or separate the stuff on different scripts.
2 - If i have to make simple animations, on some objects, like rotation when the player click on them or some kind of simple animation when they get triggered. Which one is faster:
* Do the animation with the animation editor and call the animation
* Do the animation with code (Mathf.Sin \ PingPong, etc)?
3 - Which one is faster for accessing, some object's properties or scipt, var or functions. Let's say that we have a gameObject that hit's the player...
Which one is faster for calculation from tne engine of the game on the following condition. Let's say that the Player have script called "PlayerScript".
function OnTriggerEnter(col : Collider)
{
if (col.gameObject.tag == "Player")
{
col.gameObject.SendMessage(""); (Or GetComponent)
}
}
OR:
function OnTriggerEnter(col : Collider)
{
if (col.gameObject.tag == "Player")
{
GameObject.Find("Player").SendMessage(""); (Or GetComponent)
}
}
OR:
function OnTriggerEnter(col : Collider)
{
if (col.gameObject.tag == "Player")
{
PlayerScript.SendMessage(""); (Or GetComponent)
}
}
4 - Let's say that when some objects collide, something have to change in the GameController
script, that is separate from both objects. (GameController script is attached to a
GameController gameObject). GameController script have variable named "exampleVar";
Case1: Add the gameController to the object, that is watching for collision
public var gameController : GameObject; (Here we add the gameController)
function OnTriggerEnter(col : Collider)
{
if (col.gameObject.tag == "Player")
{
gameController.GetComponent(GameController).exampleVar = 5;
}
}
Case2: Access the GameController script directly, by it's name
function OnTriggerEnter(col : Collider)
{
if (col.gameObject.tag == "Player")
{
GameController.exampleVar = 5;
}
}
____________________________________________________________________________
Your answer
Follow this Question
Related Questions
How significant is the performance difference between a jagged array and a multidimensional array? 1 Answer
game speed in the car tutorial track 1 Answer
< cheaper than <= ? 2 Answers
Are singletons in C# faster than SendMessage/GetComponent? 1 Answer
Movement speed of player is much slower in build than in the editor 3 Answers