Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Discussion Help needed

Discussion in 'Getting Started' started by titusritzki, Apr 13, 2024.

  1. titusritzki

    titusritzki

    Joined:
    Apr 13, 2024
    Posts:
    1
    I have tried to run this code:

    using UnityEngine;
    public class Cube : MonoBehaviour
    {
    void Update()
    {
    if (Input.GetKeyDown (KeyCode.D))
    GetComponent<Rigidbody>():AddTorque(0, 5, 0);
    else if (Input.GetKeyDown (KeyCode.I))
    GetComponent<Rigidbody>():AddTorque(0, -5, 0);
    }
    }

    but it won´t work because it has an error:

    Assets\Scripts\Cube.cs(9,38): error CS1513: } expected

    thanks if someone helps
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,630
    Instead of:
    GetComponent<Rigidbody>():AddTorque

    it should be:
    GetComponent<Rigidbody>().AddTorque


    (replaced
    :
    with
    .
    )
     
    Ryiah likes this.
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,065
    also for your sanity and especially ours learn to post your code with code tags..
     
    Ryiah likes this.