Search Unity

Code wrong?

Discussion in 'Scripting' started by MadJoca, Jan 18, 2019.

  1. MadJoca

    MadJoca

    Joined:
    Jan 14, 2019
    Posts:
    4
    Im coding a Flappy Bird game.

    Why I got this two message if im doing equal the tutorial? Then when I will choose the Component, doesnt apper to me the component "TapController"

    Message1 = Assets\scripts\TapController.cs(12,17): warning CS0108: 'TapController.rigidbody' hides inherited member 'Component.rigidbody'. Use the new keyword if hiding was intended.

    Message2 = Assets\scripts\TapController.cs(24,19): error CS0117: 'Input' does not contain a definition for 'getMouseButtonDown'

    Code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    [RequireComponent(typeof(Rigidbody2D))]
    public class TapController : MonoBehaviour {

    public float tapForce = 10;
    public float tiltSmooth = 5;
    public Vector3 startPos;

    Rigidbody2D rigidbody;
    Quaternion downRotation;
    Quaternion forwardRotation;

    void Start() {
    rigidbody = GetComponent<Rigidbody2D>();
    downRotation = Quaternion.Euler(0, 0, -90);
    forwardRotation = Quaternion.Euler(0, 0, 35);

    }

    void Update() {
    if (Input.getMouseButtonDown(0)) {
    transform.rotation = forwardRotation;
    rigidbody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);

    }

    transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);

    }

    void OnTriggerEnter2D(Collider2D col) {
    if (col.gameObject.tag == "ScoreZone") {
    //register a Score Event
    //play a sound
    }

    if (col.gameObject.tag == "DeadZone") {
    rigidbody.simulated = false;
    //register a dead event
    //play a sound


    }


    }


    }
     
  2. MadJoca

    MadJoca

    Joined:
    Jan 14, 2019
    Posts:
    4
    Im doing this tutorial:
     
  3. MadJoca

    MadJoca

    Joined:
    Jan 14, 2019
    Posts:
    4
    the first message disappeared when I changed the "rigidBody" to "RigidBody" but the second message still there
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Same mistake on second error. Google is your friend, search for "Input.getMouseButtonDown" and I think you'll see it.
     
  5. MadJoca

    MadJoca

    Joined:
    Jan 14, 2019
    Posts:
    4
    háá, thx man, I just put Get with G in uppercase
     
    JeffDUnity3D likes this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Errors like this should be easily visible in whatever code editor you are using.
     
  7. hassanashiq

    hassanashiq

    Joined:
    Jan 16, 2020
    Posts:
    1
    Please check my code..
    what's wrong with it

    Code (CSharp):
    1. [RequireComponent(typeof(Rigidbody2D))]
    2. public class TapController : MonoBehaviour
    3. {
    4.     public float tapForce = 10;
    5.     public float tiltSmooth = 5;
    6.     public Vector3 startPos;
    7.  
    8.  
    9.     Rigidbody2D rigidbody;
    10.     Quaternion downRotation;
    11.     Quaternion forwardRotation;
    12.  
    13.  
    14.  
    15. void Start()
    16.     {
    17.         rigidbody = GetComponent<Rigidbody2D>();
    18.         downRotation = Quaternion.Euler(0, 0, -90);
    19.         forwardRotation = Quaternion.Euler(0, 0, 35);
    20.        
    21.         //rigidbody.simulated = false;
    22.  
    23.     }
    24.  
    25.     void Update()
    26.     {
    27.         if (Input.GetMouseButtonDown(0))
    28.         {
    29.             transform.rotation = forwardRotation;
    30.             rigidbody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
    31.         }
    32.        
    33.         transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);
    34.     }
    35.  
    36.    void OnTriggerEnter2D(Collider2D col)
    37.     {
    38.         if (col.gameObject.tag == "scorezone")
    39.         {
    40.             //register a score event
    41.             //play a sound
    42.         }
    43.  
    44.  
    45.         if (col.gameObject.tag == "deadzone")
    46.         {
    47.             rigidbody.simulated = false;
    48.             //register a dead event
    49.             //play a sound
    50.         }
    51.     }
    52. }
    53.  
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you receiving an error? If so, please post it here.