- Home /
Can't follow "roll a ball" tutorial. No cube rotate or GUI count.
Even though it seems I'm following the scripts perfectly, (and I've looked it over at LEAST twice) it keeps not working. Specifically, I can't get my cubes to rotate and my GUI text to count my cubes. And when I delete the "troublesome" code that the error messages tell me aren't right, it just seems to make more errors. If anyone could try to help correct me, that would be great. THANKS!
Please post your script and someone can help you figure out compile or logic errors.
using UnityEngine; using System.Collections;
public class playercont : $$anonymous$$onoBehaviour { public float speed; public GUIText countText private int count;
void Start ()
{
count = 0;
setCountText ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce (movement * speed * Time.deltaTime);
}
void OnTriggerEnter (Collider other)
{
if(other.gameObject.tag == "pickup")
{
other.gameObject.SetActive(false);
count = count + 1;
setCountText ();
}
{
void setCountText ();
}
{
countText.text = "count: " + count.ToString ();
}
there's my script for my player controller. Here's my rotating cube script: using UnityEngine; using System.Collections;
public class Rotatah : $$anonymous$$onoBehaviour {
void update ()
{
transform.Rotate (new Vector3(15, 30, 45) * Time.deltaTime);
}
}
if you can Identify my mistakes, that would be great. The Count one is the most important one, I think.
oh, and on "using UnityEngine; using System.Collections;" they ARE separate lines.
You never declare the count variable if I'm reading this right. I'll watch the video and post the script in one sec
Answer by Destran · Mar 09, 2014 at 08:20 PM
Here's the PlayerController script from the tutorial:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public GUIText countText;
public GUIText winText;
private int count;
public float speed;
void Start ()
{
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count+1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if(count >= 12)
{
winText.text = "You Win";
}
}
}
Your rotating cube script isn't correct because "update" needs to be "Update"
like so:
function Update () {
transform.Rotate(new Vector3(15,30,45) * Time.deltaTime);
}
If adding these scripts in doesn't fix it, it's probably not a scripting problem and more likely you set something up incorrectly, try starting the tutorial over. It's pretty short so hopefully starting over won't be a total bummer.
that fixes my rotating problem, thanks. I'd up rate it thumbs up, but I'm new so I have no reputation haha.
Be sure to mark it as correct (little green check), and I thumbs uppedhis answer and thumbs upped your question so you now have enough to thumbs up his answer yourself
O$$anonymous$$, it all worked. Thanks for helping me out, now I can go on without worrying about "what did I do wrong?, how did my game get messed up?", thanks a lot!
Answer by fifthknotch · Mar 09, 2014 at 08:39 PM
Found both issues : function update needs to be function Update as @Destran pointed out.
Also, this section of your script has an unneeded } at the beginning. Hope this solved your problem.
void setCountText ();
}
{
countText.text = "count: " + count.ToString ();
}
Your answer
Follow this Question
Related Questions
How do i put lights with muzzleflash? 1 Answer
Csharp Script won't open - Roll-a-ball tutorial 1 Answer
Script not working 0 Answers
Roll-A-Ball Tutorial: Ball moves on its own 3 Answers
Burg Zerg Arcade Tutorial Help 3 Answers