- Home /
Other
my ball wont collect(rollaball)
code: using UnityEngine;
public class playercontroller3 : MonoBehaviour { public float speed;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
speed = 10.0f;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("pickup"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 12)
{
winText.text = "You Win!";
}
}
} errors: Assets/script/playercontroller3.cs(37,13): error CS0103: The name count' does not exist in the current context Assets/script/playercontroller3.cs(36,9): error CS0103: The name countText' does not exist in the current context
$$anonymous$$issing count variable field. private int count;
Compare your code with this : https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/displaying-score-and-text?playlist=17141
Answer by PKMPGHPvdvP · Sep 13, 2017 at 04:32 PM
Because you have not declared the variable count and countText. Make sure to declare them globally..
Answer by Litleck · Sep 13, 2017 at 07:38 PM
What you would do is at the top of your script in monobehaviour you would add Public int count; Then in the inspector of the object the script is put on you would set count to something.
Hope this helps!
Follow this Question
Related Questions
Roll a Ball Tutorial does not work. Help? 3 Answers
Roll-A-Ball Tutorial public float speed 1 Answer
How do I stop my camera rotating with my player? 0 Answers
New Script Assemblies not generating 0 Answers