Search Unity

Game Master Error, Missing Namespace

Discussion in 'Scripting' started by unity_UoDdgocnrRW2IA, Jul 23, 2019.

  1. unity_UoDdgocnrRW2IA

    unity_UoDdgocnrRW2IA

    Joined:
    Jul 23, 2019
    Posts:
    4
    Thank you for taking the time to look at my issue.

    Everything has worked fine up till now but now I have this error I cannot solve. I would really appreciate any and all advice as to how I can resolve this. This is the only thing stopping me from continuing my project and producing my second game.

    The error:
    Assets/Scripts/GameMaster.cs(3,27): error CS0234: The type or namespace name `ImageEffects' does not exist in the namespace `UnityStandardAssets'. Are you missing an assembly reference?

    The code looks like this:

    public class GameMaster : MonoBehaviour
    {

    public static GameMaster gm;

    void Awake()
    {
    if (gm == null)
    {
    gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    }
    }

    public Transform playerPrefab;
    public Transform spawnPoint;
    public float spawnDelay = 2;
    public Transform spawnPrefab;

    public CameraShake cameraShake;

    void Start()
    {
    if (cameraShake == null)
    {
    Debug.LogError("No camera shake referenced in GameMaster");
    }
    }

    public IEnumerator _RespawnPlayer()
    {
    GetComponent<AudioSource>().Play();
    yield return new WaitForSeconds(spawnDelay);

    Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
    GameObject clone = Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
    Destroy(clone, 3f);
    }

    public static void KillPlayer(Player player)
    {
    Destroy(player.gameObject);
    gm.StartCoroutine(gm._RespawnPlayer());
    }

    public static void KillEnemy(Enemy enemy)
    {
    gm._KillEnemy(enemy);
    }
    public void _KillEnemy(Enemy _enemy)
    {
    GameObject _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as GameObject;
    Destroy(_clone, 5f);
    cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);
    Destroy(_enemy.gameObject);
    }

    }



    Thank you for looking at my problem even if there is nothing you can advise I still appreciate it!

    I also apologize to the admins if I put this in the wrong section since I am new to the forum.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
  3. unity_UoDdgocnrRW2IA

    unity_UoDdgocnrRW2IA

    Joined:
    Jul 23, 2019
    Posts:
    4
    Thank you for the link! I was not aware of this before. Here is the revised version.

    Code (CSharp):
    1. public class GameMaster : MonoBehaviour
    2. {
    3.  
    4. public static GameMaster gm;
    5.  
    6. void Awake()
    7. {
    8. if (gm == null)
    9. {
    10. gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    11. }
    12. }
    13.  
    14. public Transform playerPrefab;
    15. public Transform spawnPoint;
    16. public float spawnDelay = 2;
    17. public Transform spawnPrefab;
    18.  
    19. public CameraShake cameraShake;
    20.  
    21. void Start()
    22. {
    23. if (cameraShake == null)
    24. {
    25. Debug.LogError("No camera shake referenced in GameMaster");
    26. }
    27. }
    28.  
    29. public IEnumerator _RespawnPlayer()
    30. {
    31. GetComponent<AudioSource>().Play();
    32. yield return new WaitForSeconds(spawnDelay);
    33.  
    34. Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
    35. GameObject clone = Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
    36. Destroy(clone, 3f);
    37. }
    38.  
    39. public static void KillPlayer(Player player)
    40. {
    41. Destroy(player.gameObject);
    42. gm.StartCoroutine(gm._RespawnPlayer());
    43. }
    44.  
    45. public static void KillEnemy(Enemy enemy)
    46. {
    47. gm._KillEnemy(enemy);
    48. }
    49. public void _KillEnemy(Enemy _enemy)
    50. {
    51. GameObject _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as GameObject;
    52. Destroy(_clone, 5f);
    53. cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);
    54. Destroy(_enemy.gameObject);
    55. }
    56.  
    57. }
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What line is the error? The code you posted doesn't mention ImageEffects. Also the point of posting with CODE tags is to properly format the code as seen in something like visual studio. All you've done is just add line numbers to it, and they don't even line up with the error message. Take a look at other threads what people are doing.

    This:
    Code (csharp):
    1. void Awake()
    2. {
    3. if (gm == null)
    4. {
    5. gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    6. }
    7. }
    Should look like this:
    Code (csharp):
    1. void Awake()
    2. {
    3.     if (gm == null)
    4.     {
    5.         gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    6.     }
    7. }
    You're asking for free help, do people the courtesy of not making reading your code more difficult than it has to be. Low effort posts get low effort responses (or usually none at all). Post the code in the same readable form you'd want if you were reading it, and state what line the error is referring to.
     
    Last edited: Jul 24, 2019
  5. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,635
    Do you have a "using" statement on line 3? The error message says that error is on line 3 but I assume that you left off that line since your listing has no "using" block.

    It looks like maybe you are trying to reference Unity's old image effects library without having it installed. Since you are not actually using any of the image effects, you can just delete any "using" statement that mentions it.
     
  6. unity_UoDdgocnrRW2IA

    unity_UoDdgocnrRW2IA

    Joined:
    Jul 23, 2019
    Posts:
    4
    Sorry Joe-Censored it is my first time using this forum and I have little to no experience in C# in general.

    kdgalla - Downloading the older image effects solved one issue but created another.

    The new error looks like this:
    Assets/Scripts/GameMaster.cs(38,95): error CS0039: Cannot convert type `UnityEngine.Transform' to `UnityEngine.GameObject' via a built-in conversion

    This same error is repeated for line (54,112)

    The code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityStandardAssets.ImageEffects;
    4.  
    5. public class GameMaster : MonoBehaviour
    6. {
    7.  
    8.     public static GameMaster gm;
    9.  
    10.     void Awake()
    11.     {
    12.         if (gm == null)
    13.         {
    14.             gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
    15.         }
    16.     }
    17.  
    18.     public Transform playerPrefab;
    19.     public Transform spawnPoint;
    20.     public float spawnDelay = 2;
    21.     public Transform spawnPrefab;
    22.  
    23.     public CameraShake cameraShake;
    24.  
    25.     void Start()
    26.     {
    27.         if (cameraShake == null)
    28.         {
    29.             Debug.LogError("No camera shake referenced in GameMaster");
    30.         }
    31.     }
    32.  
    33.     public IEnumerator _RespawnPlayer()
    34.     {
    35.         GetComponent<AudioSource>().Play();
    36.         yield return new WaitForSeconds(spawnDelay);
    37.         Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
    38.         GameObject clone = Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
    39.         Destroy(clone, 3f);
    40.     }
    41.  
    42.     public static void KillPlayer(Player player)
    43.     {
    44.         Destroy(player.gameObject);
    45.         gm.StartCoroutine(gm._RespawnPlayer());
    46.     }
    47.  
    48.     public static void KillEnemy(Enemy enemy)
    49.     {
    50.         gm._KillEnemy(enemy);
    51.     }
    52.     public void _KillEnemy(Enemy _enemy)
    53.     {
    54.         GameObject _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as GameObject;
    55.         Destroy(_clone, 5f);
    56.         cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);
    57.         Destroy(_enemy.gameObject);
    58.     }
    59.  
    60. }
    61.  

    Thank you both for your responses! I appreciate the advice!
     
  7. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    If you're wanting to instantiate a prefab, then you should reference a GameObject, not a Transform (IMO), and drag the prefab object into that slot in the inspector. Change the types on lines 18 and 21 to GameObjects instead and the rest should work as written.

    Note that you can instantiate the prefab from a Transform as you do here (though it's a bit odd to do so), but then you have to assign the result to a Transform reference, or use result.gameObject. In that case, line 38 would become something like:
    Code (csharp):
    1. Transform clone = (Transform)Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation);
    2.  
    3. - or -
    4.  
    5. GameObject clone = ((Transform)Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation)).gameObject;
     
    Last edited: Jul 25, 2019
    unity_UoDdgocnrRW2IA likes this.
  8. unity_UoDdgocnrRW2IA

    unity_UoDdgocnrRW2IA

    Joined:
    Jul 23, 2019
    Posts:
    4
    Thank you so much Lysander! This issue bogged me down for 4 days and I could not figure it out. You saved my day!
     
  9. akositheflash01

    akositheflash01

    Joined:
    Apr 10, 2021
    Posts:
    1
    How about upload_2021-6-7_11-17-19.png this ? Can someone please help me?