#could anyone tell me how i could make it so that, you as a player, can change the values of a field

1 messages · Page 1 of 1 (latest)

upbeat lantern
#

i want to change these values as a player

#

this is my code

#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class dogMaker : MonoBehaviour
{
    public class dog
    {
        public string name;
        public int age;
        public string race;


        public dog(string _name, int _age, string _race)
        {
            name = _name;
            age = _age;
            race = _race;
        }

    }
    public dog dog1 = new dog("Josh", 5 , "German Sheppard");
    public void Start()
    {
        Debug.Log(dog1.name + " has been created with the race set to " + dog1.race + " and is " + dog1.age + " years old.");
    }
}
#

offline in 13min

meager obsidian
#

Just

dog1.name = "...";
...
upbeat lantern
#

wdym?

vestal solar
#

Like you want that the player should give a name to the dog ?

#

Then for the name you need an input field component on the UI so that the player can enter the name and some scripting.
For the age it needs some some small scripting
For the race some scripting also

upbeat lantern
#

so i should do something like a keyboard?

#

for the name

crimson marsh
#

That is up to you.
If you use the built-in UI input field (or better the TMP one) though, you will be able to simply enter text with the physical keyboard (or the system keyboard on mobile).

upbeat lantern
#

thnx did not know that