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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Instantiate an object from a static script?

Discussion in 'Prefabs' started by Snownebula, Mar 14, 2019.

  1. Snownebula

    Snownebula

    Joined:
    Nov 29, 2013
    Posts:
    174
    I am having some problems instantiating an object from a static script. I am not quite sure what to do about this.
    This is where I am trying to do it at:

    Code (CSharp):
    1. public static void SpawnShip()
    2.     {
    3.      
    4.         PlayerName = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent<NetworkClientManagerHUD>().playerName;
    5.         if (NetworkClientManagerHUD.playerName == "Snow")
    6.         {
    7.             Destroy(GameObject.FindGameObjectWithTag("DestroyMe"));
    8.             Instantiate(shipList.shipS001, GameObject.FindGameObjectWithTag("Spawns/Gates/1-50/001").transform.position, transform.rotation);
    9.             MouseOrbit2.playerTarget = GameObject.FindGameObjectWithTag("Player");
    10.             target = MouseOrbit2.playerTarget.transform;
    11.             Debug.LogWarning("Client is running!");
    12.             return;
    This is the script I'm trying to get it from:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class shipList : MonoBehaviour {
    7.     public GameObject ship000;
    8.     public GameObject ship001;
    9.     public GameObject ship002;
    10.     public GameObject ship003;
    11.     public GameObject ship004;
    12.  
    13.     // STATIC LIST
    14.     public static GameObject shipS000;
    15.     public static GameObject shipS001;
    16.     public static GameObject shipS002;
    17.     public static GameObject shipS003;
    18.     public static GameObject shipS004;
    19.  
    20.     void Awake()
    21.     {
    22.         shipS000 = ship000;
    23.         shipS001 = ship001;
    24.         shipS002 = ship002;
    25.         shipS003 = ship003;
    26.         shipS004 = ship004;
    27.         Debug.LogWarning("Ship 0: " + shipS000);
    28. }
    29. }
    If anyone has any ideas it would be greatly apricated..