Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MyScript : MonoBehaviour
- {
- // Always call this to create MyScript objects so we know they are complete.
- public static MyScript Create(
- string resourcesPath,
- string additionalArgument1,
- int otherArgument)
- {
- // NOTE: only have ONE of the following two blocks of code, not both:
- // Option 1:
- // code for if this is a pre-defined prefab that you're going
- // to load, instantiate, and then customize a bit.
- // You can also keep its source path private to this class.
- GameObject go = Resources.Load<GameObject>( resourcesPath);
- go = Instantiate<GameObject>( go);
- MyScript myScript = go.GetComponent<MyScript>();
- // Option 2:
- // code for making a new GameObject from scratch
- //MyScript myScript = new GameObject( "MyScript.Create();").
- // AddComponent<MyScript>();
- // jam in the arguments we need (remember, Awake has already executed!!)
- myScript.additionalArgument1 = additionalArgument1;
- myScript.otherArgument = otherArgument;
- return myScript;
- }
- string additionalArgument1;
- int otherArgument;
- void Start()
- {
- /// etc...
- }
- void Update()
- {
- /// etc...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment