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

Getting a unique number using Guid?

Discussion in 'Editor & General Support' started by brolol404, Dec 6, 2020.

  1. brolol404

    brolol404

    Joined:
    Feb 14, 2015
    Posts:
    21
    Any help with this error?
    Assets\Scripts\CreatureStats.cs(13,34): error CS0119: 'Guid.NewGuid()' is a method, which is not valid in the given context

    Am I missing a namespace or am I just using Guid wrong?

    I am trying to get a unique number.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CreatureStats : MonoBehaviour
    6. {
    7.     public string CreatureID;
    8.  
    9.     void Start()
    10.     {
    11.         CreatureID = System.Guid.NewGuid.ToString();
    12.         Debug.Log("CreatureID: " + CreatureID);
    13.     }
    14. }
    15.  
     
  2. brolol404

    brolol404

    Joined:
    Feb 14, 2015
    Posts:
    21
    figured it out:

    CreatureID = System.Guid.NewGuid().ToString();