Search Unity

Roll-a-Ball Issues

Discussion in 'Community Learning & Teaching' started by oedze, Apr 21, 2014.

  1. oedze

    oedze

    Joined:
    Apr 21, 2014
    Posts:
    2
    Hello

    I was doing the Roll-a-Ball tutorial today, and i got 2 errors i can't understand or fix. Can someone help me out?

    PlayerController.cs code:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.  
    7.  
    8.     public float speed;
    9.     public GUIText CountText;
    10.     public GUIText WinText;
    11.     private int count;
    12.  
    13.     void start(){
    14.         count = 0; 
    15.         setCountText ();
    16.         WinText.text = "";
    17.     }
    18.  
    19.     void FixedUpdate(){
    20.         float moveHorizontal = Input.GetAxis ("Horizontal");
    21.         float moveVertical = Input.GetAxis ("Vertical");
    22.  
    23.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    24.  
    25.         rigidbody.AddForce (movement * speed * Time.deltaTime);
    26.     }
    27.     void OnTriggerEnter(Collider other){
    28.         if (other.gameObject.tag == "PickUp") {
    29.             other.gameObject.SetActive(false);
    30.             count = count + 1;
    31.             setCountText ();
    32.         }
    33.     }
    34.     void setCountText()
    35.     {
    36.         CountText.text = "Count: " + count.ToString();
    37.         if (count => 12) {
    38.             WinText.text = "YOU WIN!!!";
    39.         }
    40.     }
    41. }
    42.  
    errors:
    Assets/Scripts/PlayerController.cs(36,21): error CS1660: Cannot convert `lambda expression' to non-delegate type `bool'

    Assets/Scripts/PlayerController.cs(35,46): error CS0135: `count' conflicts with a declaration in a child block

    Thanks.
     
  2. adamazing

    adamazing

    Joined:
    Aug 15, 2013
    Posts:
    2
    Hi there,
    If you haven't already struck upon the answer, line 36:
    Code (csharp):
    1. if (count => 12) {
    should be:
    Code (csharp):
    1. if (count >= 12) {
    ">=" is the boolean expression "Greater than or Equal to" which I'm guessing is what you want! :)

    "=>" is used in the definition of lambda expressions in C# and cannot be converted to type `bool' (first error). The compiler even points you to the line/character position you should be looking at ;)

    This propagates and causes the second error as I'm guessing the compiler thinks you mean to replace the earlier declaration at Line 10 with your lambda expression, which of course has no concept of ToString().

    Hope that helps,
    Adam

    (I've been programming a while but I'm just starting to use C# so I might be a little off with my explanations; hopefully someone will correct me if I'm wildly off-base!)
     
  3. oedze

    oedze

    Joined:
    Apr 21, 2014
    Posts:
    2
    thanks, that's a hard to find bug if you're new to the language :)