I’m having doubts on how to use the "{" keys

Asked

Viewed 39 times

-4

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


public class MOVIMENTO : MonoBehaviour
{
private float spd = 0.9f;
private GameObject camera;
private GameObject gameOverUI;
public bool gameOver;
// Start is called before the first frame update
void Start()
{
camera = GameObject.Find("Camera");
gameOver = false;
gameOverUI = GameObject.Find("GAME OVER");
gameOverUI.gameObject.active - false;
}

// Update is called once per frame
void Update()
{
if (gameOver == false) {
//camera.transform.position = transform.position - new Vector3(-12f ,-3 ,0 );
//if (Input.GetKey("w"))
transform.position += new Vector3(-spd ,0 ,0 );

if (Input.GetKey("d"))
transform.position += new Vector3(0 ,0 ,spd );
//if (Input.GetKey("space"))
//transform.position += new Vector3(0 ,2 ,0 );

if (Input.GetKey("a"))
transform.position += new Vector3(0 ,0 ,-spd );

//if (Input.GetKey("space"))
//transform.position += new Vector3(0 ,2 ,0 );
//NITRO
//if (Input.GetKey("c"))
//transform.position += new Vector3(-1 ,0 ,0 );

if (Input.GetKey("e"))
Debug.Log("PRESTOU!");

public void OnCollisionEnter(Collision obj){
if (obj.gameObject.tag == "POLICIAL BOSTA") {
gameOverUI = gameObject.active = true;
gameOver = true;
Application.LoadLevel(Application.loadedLevel);
Debug.Log("JAERA!");


if (obj.gameObject.tag == "Caio") {
transform.position += new Vector3(0 ,2 ,0 );

//if (obj.gameObject.tag == "Vitor") {
//transform.position += new Vector3(-4 ,0 ,0 );
//}
//if (obj.gameObject.tag == "Arta") {
//transform.position += new Vector3(0 ,2 ,0 );
//}
if (obj.gameObject.tag == "Fim da linha") {
Application.LoadLevel(Application.loadedLevel);

if (obj.gameObject.tag == "NITRO") {
transform.position += new Vector3(-9 ,0 ,0 );
}
}
}

I’m trying to make a game in Unity, only q ta giving error to open and close keys "{}" ai n da to run the game because of this,:

Assets MOVIMENTO.Cs(46,5): error CS0106: The Modifier 'public' is not Valid for this item

what I do to solve?

  • Start writing your code.

  • After the Debug.Log("JAERA!"); missing one }

1 answer

1

I have indented your code and removed keys that you opened but not closed and that is why it gave rise to a major mistake which was the function 'Oncolisionenter' have no key to close!

Start doing indentation in their codes, this helps in organization and in the readability of the code!

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


public class MOVIMENTO : MonoBehaviour
{
    private float spd = 0.9f;
    private GameObject camera;
    private GameObject gameOverUI;
    public bool gameOver;
    // Start is called before the first frame update
    void Start()
    {
        camera = GameObject.Find("Camera");
        gameOver = false;
        gameOverUI = GameObject.Find("GAME OVER");
        gameOverUI.gameObject.active - false;
    }

    // Update is called once per frame
    void Update()
    {
        if (gameOver == false) 
            //camera.transform.position = transform.position - new Vector3(-12f ,-3 ,0 );
            //if (Input.GetKey("w"))
            transform.position += new Vector3(-spd ,0 ,0 );

        if (Input.GetKey("d"))
            transform.position += new Vector3(0 ,0 ,spd );
            //if (Input.GetKey("space"))
            //transform.position += new Vector3(0 ,2 ,0 );

        if (Input.GetKey("a"))
            transform.position += new Vector3(0 ,0 ,-spd );

        //if (Input.GetKey("space"))
            //transform.position += new Vector3(0 ,2 ,0 );
            //NITRO
        //if (Input.GetKey("c"))
            //transform.position += new Vector3(-1 ,0 ,0 );

        if (Input.GetKey("e"))
            Debug.Log("PRESTOU!");
    }

    public void OnCollisionEnter(Collision obj){
        if (obj.gameObject.tag == "POLICIAL BOSTA"){
            gameOverUI = gameObject.active = true;
            gameOver = true;
            Application.LoadLevel(Application.loadedLevel);
            Debug.Log("JAERA!");
        }

        if (obj.gameObject.tag == "Caio") 
            transform.position += new Vector3(0 ,2 ,0 );

        //if (obj.gameObject.tag == "Vitor")
            //transform.position += new Vector3(-4 ,0 ,0 );

        //if (obj.gameObject.tag == "Arta")
            //transform.position += new Vector3(0 ,2 ,0 );

        if (obj.gameObject.tag == "Fim da linha")
            Application.LoadLevel(Application.loadedLevel);

        if (obj.gameObject.tag == "NITRO")
            transform.position += new Vector3(-9 ,0 ,0 );
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.