look i was looking like everywhere and nothing helped me i just need an integer i tried GameController and creaing an empty game object nothing worked
also i am new to unity and c#
Make a new script, make a public int inside the class’ curly braces { }, drag and drop the script on your empty game object. Like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SomeClass : MonoBehaviour
{
public int myInteger = 162;
}
I would highly recommend taking a C# fundamentals tutorial series on Youtube before diving in to this, or use https://learn.unity.com/.
It’s going to be a massive struggle otherwise.
Welcome, and good luck!
If you say you’ve tried looking everywhere without specific examples we can do generally do very little except link to a tutorial which you may or may not have already tried. Pick one approach you’ve attempted, and then describe in what way that approach didn’t work.
Hey Tobik,
as I don’t have too much information, I’d like to point you in two possible ways:
A) Singletons
B) ScriptableObjects
The later might be the better solution for you as it’s easier but as we don’t have too much information about your requirements, I might be totally wrong.
Here a link for a start:
When I try to make a public int there a error saying “{ expected” and I’m doing nothing wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject[] prehabsIndex;
public int animalIndex = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (GetKeyDown.(KeyCode.S))
{
instantiate(prehabsIndex[animalIndex], new Vector3(0, 0, 20), prehabsIndex[animalIndex]);
}
}
Except that you’re a) necro-posting and b) forgetting to put a semicolon after your statement.
What do you mean I put a semicolon after my public int statement
What is the method GetKeyDown.? There is no such thing in Unity.
You have Input.GetKeyDown.
What is ___i___nstantiate? With a small “i”? Because the Unity method is with capital “I”.
Please create your own thread and don’t necropost.
Thanks.