Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Separate script?

Discussion in 'Scripting' started by Dzxyan, Jun 12, 2014.

  1. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    I like to write the script code in a files,
    when i finish the scripting it maybe use 2000++ line,
    it will affect the performance?
    many of the code is use for many function, so that why i didn't separate it become multiple script.
    if i separate it become multiple,
    i need to call a lot of time if get a function run,
    it will drop down performance?
     
    Sh-O578 likes this.
  2. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    Having a lot of code in your script will not visibly affect the performance of your game in any way. Having the code split between multiple scripts and having a lot of calls between them will also not affect the performance, but trust me when I say this: if you split the code properly, you will have a much easier time changing the code, maintaining and improving it. So, if I were you, I would choose to split my code in multiple scripts.
     
    Sh-O578 likes this.
  3. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    Thanks for reply,
    but when you need call other scripts,
    you will use getComponent or Instance?
    or you have other better way?
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    Use GetComponent() once in the Start() function of the script and store the result in a variable. Then you can access the object throughout the script using that variable with no loss in performance.
     
    Landern likes this.