- Home /
Roll a ball tutorial problems ,, i'm a beginner pls help ..
hello i have some small issues with this code ....
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public Rigidbody rb;
public float speed;
public Text countText;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText();
}
void FixedUpdate()
{
float moveHorizaontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizaontal, 0.0f, moveVertical);
rb.AddForce (movement * speed *Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive(false);
count=count+1;
SetcountText();
}
}
void SetcountText();
{
countText.text="count: " + count.ToString();
}}
Errors ...
1)Assets/_scripts/PlayerController.cs(34,9): error CS1519: Unexpected symbol {' in class, struct, or interface member declaration 2)Assets/_scripts/PlayerController.cs(35,23): error CS1519: Unexpected symbol
=' in class, struct, or interface member declaration
3)Assets/_scripts/PlayerController.cs(35,50): error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration
Pls help me out i can't figure out what is it !! :(
Answer by saravanan-P · Jun 11, 2015 at 08:50 AM
u should insert something in countText...
like this for example,
Answer by tanoshimi · Jun 09, 2015 at 01:11 PM
void SetcountText();
Don't put a semicolon after a method signature.
ok didn't see that ;) now it works like a code,but the game stops every time i collect a pickup object... it'says like this ----NullReferenceException: Object reference not set to an instance of an object PlayerController.SetcountText () (at Assets/_scripts/PlayerController.cs:35) PlayerController.Start () (at Assets/_scripts/PlayerController.cs:14)
drag and drop your text object to your public CountText in the inspector.
Answer by Keygen91 · Jun 12, 2015 at 10:44 AM
thanks bro ,, i resolved ...i'm new to unity (just 1 week) and i'll post a lot of stupid questions ... but 1 day i'll help you all :)
Your answer
Follow this Question
Related Questions
Help with making a triggered gui message 1 Answer
Break the limits on text area 0 Answers
Unity crashes at writing TextMesh? 0 Answers
The variable m_Font of 'GUISkin' doesn't exist anymore 1 Answer