how to transfer C# data?

I have these two scripts
using UnityEngine;
using System.Collections;

public class Boxes : MonoBehaviour {
 
private int collected = 0; //Set up a variable to store how many you've collected
 
public Transform EndZone; //Drag GameObject which should be animated in here.
 
public AudioClip collectedSound; //This is the sound that will play after you collect one
 
public GUIStyle mystyle;
 
//This is the text that displayed how many you've collected in the top left corner
 
void OnGUI(){
 
GUI.Label(new Rect(40, 10, 500, 500),"Boxes:" + collected + "/14", mystyle);
 
}
 
 
 
private void OnTriggerEnter(Collider other){ //Checks to see if you've collided with another object
 
if(other.CompareTag("collectable")){ //checks to see if this object is tagged with "collectable"
 
audio.PlayOneShot(collectedSound); //plays the sound assigned to collectedSound
 
collected++; //adds a count of +1 to the collected variable
 
if(collected == 14){
  //Play Animation here like for example:
  EndZone.animation.Play("Collectedall"); //Change AnimationName to the name of your animation.
}
 
Destroy (other.gameObject);}}}

and

using UnityEngine;
using System.Collections;

public class GemChecks : MonoBehaviour{
public int GemColour;
	private void
if(Gems.ColourID == 0)}

(not sure what will happen after the if)
and i get this message with the second script

invalid token ‘if’ class,struct or interface member declaration.
(the same goes for the ==)
i’m not sure what is wrong so could somebody please tell me.

2 Answers

2

The if statement expects a statement to follow. Until you know what the if statement will do just comment it out :slight_smile:

I tried putting somethings after the last line but it didn't change anything

Please post the updated script.

This script is slightly different to the one shown above but it has the same problem using UnityEngine; using System.Collections; public class GenerateFinishGUI : MonoBehaviour { public GUIStyle mystyle; if (LapCount.checkpoints == 25) void OnGUI(){ GUI.Label (new Rect(0, 0, 500, 500),"Finish!", mystyle);}}

OK. First, did you read the link I provided? It seems like you are having a hard time understanding statements and blocks. What you have here declares an if statement in the body of a class which is illegal ( it needs to be in a method ) and then declares a method in the if statement... Seems like you really need to get to the basics of scripting. Read this tutorial and then try again! http://wiki.unity3d.com/index.php?title=CSharp_Unity_Tutorial

There is nothing inside your if statement in your second script, line 7