'How do I add unity script settings?
how do I make a script, that when attached to an object, you can change the settings of it under the script, like a number value or string?
Solution 1:[1]
You need to add the variables in public visibility.
Source: Variables and the Inspector
For instance:
using UnityEngine;
using System.Collections;
public class MainPlayer : MonoBehaviour
{
public string myName;
// Use this for initialization
void Start ()
{
Debug.Log("I am alive and my name is " + myName);
}
}
You can now change "the settings" of the variable myName when attached to an object.
Solution 2:[2]
There are basically two options, either making the variable public or using the [SerializeField] attribute. The best practice is to use [SerializeField] if you're not going to access the variable outside the class.
1: public string exposedString;
2: [SerializeField] private string serializedString;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yannis Sauzeau |
| Solution 2 | Antônio Pedro |
