Hello evreybody, I have another problem, when I create the GameCenter it appears this:
“Assets/GameCenter.cs(30,17): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer”
what I need to do?
using UnityEngine;
using System.Collections;
public class GameCenter : MonoBehaviour {
public static int PlayerScore1=0;
public static int PlayerScore2=0;
public GUISkin layout;
Transform theBall;
//Usethisfor initialization
void Start () {
theBall = GameObject.FindGameObjectWithTag("Ball").transform;
}
public static void Score (string wallID) {
if (wallID == "rightWall") {
PlayerScore1++;
} else {
PlayerScore2++;
}
}
void OnGui(){
GUISkin = layout;
GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "Player1" + PlayerScore1);
GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "Player2" + PlayerScore2);
if (GUI.Button (new Rect (Screen.width / 2 - 60, 35, 120, 53), "RESET")) {
PlayerScore1 = 0;
PlayerScore2 = 0;
theBall.gameObject.SendMessage ("resetBall", .5f, SendMessageOptions.RequireReceiver);
}
if (PlayerScore1 == 10) {
GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "Player1WINS");
theBall.gameObject.SendMessage ("hasWon", null, SendMessageOptions.RequireReceiver);
}else if (PlayerScore2 == 10){
GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "Player2WINS");
theBall.gameObject.SendMessage ("hasWon", null, SendMessageOptions.RequireReceiver);
}
}
}
Line 30 doesn’t make any sense, which is what the error is pointing to.
GUISkin
is a class, not an lvalue; you can’t attempt to set it equal to anything. I’m not actually even sure what you were trying to do there, can you explain?
If you’re not sure, try removing this line from your script.
I want to make the score for the pong game, but it’s impossibile with this problem
I eliminate the thing and it works, but now i have this one:
UnityException: Tag: Ball is not defined.
GameCenter.Start () (at Assets/GameCenter.cs:16)
using UnityEngine;
using System.Collections;
public class GameCenter : MonoBehaviour {
public static int PlayerScore1=0;
public static int PlayerScore2=0;
public GUISkin layout;
Transform theBall;
//Usethisfor initialization
void Start () {
theBall = GameObject.FindGameObjectWithTag("Ball").transform;
}
public static void Score (string wallID) {
if (wallID == "rightWall") {
PlayerScore1++;
} else {
PlayerScore2++;
}
}
void OnGui(){
GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "Player1" + PlayerScore1);
GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "Player2" + PlayerScore2);
if (GUI.Button (new Rect (Screen.width / 2 - 60, 35, 120, 53), "RESET")) {
PlayerScore1 = 0;
PlayerScore2 = 0;
theBall.gameObject.SendMessage ("resetBall", .5f, SendMessageOptions.RequireReceiver);
}
if (PlayerScore1 == 10) {
GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "Player1WINS");
theBall.gameObject.SendMessage ("hasWon", null, SendMessageOptions.RequireReceiver);
}else if (PlayerScore2 == 10){
GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "Player2WINS");
theBall.gameObject.SendMessage ("hasWon", null, SendMessageOptions.RequireReceiver);
}
}
}
Lollo_92:
I eliminate the thing and it works, but now i have this one:
UnityException: Tag: Ball is not defined.
GameCenter.Start () (at Assets/GameCenter.cs:16)
“Tags must be declared in the tag manager before using them. A UnityException will be thrown if the tag does not exist or an empty string or null is passed as the tag.”
__*http://docs.unity3d.com/ScriptReference/GameObject.FindWithTag.html*__