C# don´t work

Does anybody that is wrong?

using UnityEngine;
using System.Collections;

public class SceneGUI : MonoBehaviour {
	public Material[] mats;
	public GameObject ga;
	private int index = 0;
	
	void Start () {
		ga.tender.material = mats[index];
	}
	
	
	public void OnGUI() {
		GUILayout.BeginArea(new Rect(Screen.with / 2 - 100, Screen.height - 60, 200, 50));
		    GUI.Box(new Rect(10, 10, 190, 40),"");
		    
		    GUI.Label(new Rect(62, 20, 100, 20), "Stone Texture" + (index + 1));
		    
		    if(GUI.Button(new Rect(15, 15, 30, 30), "<<")){
		    	index--;
		    	if(index < 0) {
		    		index = mats.length - 1;
		    	}
		    	ga.renderer.material = mats[index];
		    }
		    
		    if(GUI.Button(new Rect(165, 15, 30, 30); ">>")){
		    	index++;
		    	if(index > mats.Length - 1) {
		    		index = 0;
		    	}
		    	ga.renderer.material - mats[index];
		    }
		GUILayout.EndArea ();
	}
}

Well, hello first ! :slight_smile:

Then, what isn’t working ? Script error ? GUI not properly rendered (in this case, maybe switch to GUI forum).

and maybe if you use GUILayout Area, you should use GUILayout functions for Label, Button, Box…

The first problem is you aren’t posting your actual error or symptoms.

A lot of things are wrong with your code.

I will assume that you know enough to fix those on your own.

EDIT: The bolded characters aren’t too visible on the fourth and fifth lines. On the fourth line, the semi-colon is bolded. On the fifth line, the dash is bolded.

ga.tender.material = mats[index];
->
ga.renderer.material = mats[index];

GUILayout.BeginArea(new Rect(Screen.with / 2 - 100, Screen.height - 60, 200, 50)); 
->
GUILayout.BeginArea(new Rect(Screen.width / 2 - 100, Screen.height - 60, 200, 50));

index = mats.length - 1;
->
index = mats.Length - 1;

if(GUI.Button(new Rect(165, 15, 30, 30); ">>")){ 
->
if(GUI.Button(new Rect(165, 15, 30, 30), ">>")){

ga.renderer.material - mats[index]; 
->
ga.renderer.material = mats[index];

This is an illustration of the errors you are getting. (which you NEED to look at before you post “I can’t figure out what is wrong”)

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {
	GameObject ga;
	Material[] mats;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		int index=0;
		ga.tender.material = mats[index];
	}
}

produces this error:

Assets/test.cs(15,20): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `tender' and no extension method `tender' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)

and it flat tells you… “tender is NOT part of a GameObject”

Look at the reference:

The others are a little harder.

The length is because the actual length of a Material[ ] is Length with a capitol L.
Screen.with, of course should be Screen.width
In your GUI.Button, you have accidentally put a semicolon in where a comma should have been.
And the last one is you accidentally hit minus instead of equals.

We all make dumb little mistakes. The only difference is that the vets look at the Console every time they save a piece of script out. I make so many dumb mistakes it can get real slow. We all understand being frustrated, but use the tools you have, and it will get better.

I’ve never seen a mistake in the console, then again I code much better than we’re seeing in this thread.

Unity is always as correct as it can be, considering what you’re giving it. Sometimes the error may not seem to apply because your syntax errors confuse the parser, but the point is that you should always say what the errors are. “It doesn’t work” isn’t very helpful.

–Eric

Unless you added more stuff to your code since you posted it, you should not have any errors at all since I pointed out all your errors and BigMisterB told you how to fix them.

You posted a class called test but the errors are from Assets/NewBehaviourScript.cs
Unity does not make mistakes in the console.

I think with a little bit of time and work, you should be able to fix your problem. You obviously don’t want to invest much time on this and make absolutely no effort to explain what’s wrong with your code.

I still don’t understand why people continue to help you :slight_smile:

It’s a waste of our time helping you if you’re not going to sit down and follow some tutorials to learn how to program first. I may be wrong, but this site isn’t to teach how to program from scratch. There’s limits, and I feel you need to learn to walk, before you can run, like a simple hello world app, and moving onto bigger things.

Right now you’re just wanting to code this whole game and believing your friends or whatever (they’re wrong).

your right, if the OP doesnt know how to code/program he wont be able to make a game.

It might REALLY help if you took a screenshot of the console with this error or copy and paste the error message.