using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour {
[B] public List<GameObject> Bloques = new List<GameObject>();
static System.Random list = new System.Random();[/B]
void Awake()
{
int x = list.Next(9);
}
void Update()
{
if (Input.GetMouseButtonDown(0)) {
int x = list.Next(9);
switch (x)
{
case 0:
GameObject.FindWithTag("Base1");
print("0");
break;
case 1:
print("1");
break;
case 2:
print("2");
break;
case 3:
print("3");
break;
case 4:
Debug.Log("4");
break;
case 5:
Debug.Log("5");
break;
case 6:
Debug.Log("6");
break;
case 7:
Debug.Log("7");
break;
case 8:
Debug.Log("8");
break;
}
}
}
/*public GameObject GetGameObject_FromBloques(string name)
{
foreach (GameObject gameObject in Bloques)
{
if (gameObject.name == name)
{
return gameObject;
}
}
Debug.LogError("Game Object not found in Bloques!");
return null;
}*/
}
Hey there. Post #135 and still not using code tags
Opening multiple threads, not saying when they are completed at least half of the time⌠sigh.
Bloques[x]. // etc.. don't even need a switch here.
yes i need xdd
Okay, well you changed the post (glad you finally got the tags working).
From which list are you trying to change the colour of the game object ?
The Bloques list or something else?
yup the bloques list but idk how to use it because ona rrays should be bloques[0]; (for ex) but here dont work and i didnt find anything ![]()
Do you fill the List in the inspector?
Lists can be indexed just like arrays, provided that the index is valid.
sureâŚ
public Color naranja;
public Color basen;
void Awake()
{
int x = list.Next(9);
}
void Update()
{
if (Input.GetMouseButtonDown(0)) {
int x = list.Next(9);
switch (x)
{
case 0:
GameObject.FindWithTag("Base1");
gameObject.GetComponent<Renderer>().material.color = naranja;
i try this dont work ![]()
error on unirt
There is no âRendererâ attached to the âGameObjectâ game object, but a script is trying to access it.
You probably need to add a Renderer to the game object âGameObjectâ. Or your script needs to check if the component is attached before using it.
test.Update () (at Assets/test.cs:26)
Here, my best suggestion would be:
Get a little more comfortable with the basics of Unity + scripting and you wonât be trapped on such simple issues as you make your own games/projects. Good luck ![]()
first i speak spaanish then if u want a good learn u have to pay and they say âScripting is a skill that takes some time and effort to learn. The intention of this section is not to teach you how to write script code from scratch, but rather to explain the main concepts that apply to scripting in Unity.â
Donât know what you mean about paying for the tutorials. And I realize that itâs not the be all, end all of programming (on the Unity site), but you have many small issues because youâre starting out (Iâve been there, too).
For instance, youâre calling a GameObject.Find without assigning the return value.
Youâre looking up a component on the (current) game object, instead of the one in the list (or the found that you presumably tried to find in the previous line), and also youâre switching on a list (index) but not using that resultâŚ
Iâm only trying to be helpful.
Okay, I wasnât talking about that part, though.
Anyways, if you want donât want to do the tutorials, thatâs your choice; as I said, I was only offering a suggestion & trying to be helpful.
Did the things I pointed out help you at all to understand whatâs wrong/how to fix it?
what tutorials xD? only return to here https://docs.unity3d.com/ScriptReference/index.html and give u all the api no videos or exercise i think
I was referring to:
https://unity3d.com/learn/tutorials
and: https://unity3d.com/learn/live-training
Of course the manual and API are good, too ![]()
yea but like i say i speak spanish xdd anyway i cant do it yet :/, i am trayng all for change the color of object [0]
Bloques[x].GetComponent<Renderer>().material.color = naranja
for learn u use only learn from unity ? i mean if u know some channel on yt pls share jaja and ty!! it work
For me, personally, Iâve studied programming in general on and off for years (c and C#). When I came to Unity, I tried to learn about the methods, API, manual and how to use the editor. Iâm still learning, too ![]()
But yes, Iâve watched some tutorials and practiced. ![]()