using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerControls : MonoBehaviour [Header("Game Controller Object for controlling the game")] public GameController gameController; [Header("Default Velocity")] public float velocity = 1; private Rigidbody2D rb; private float objectHeight; { void Start() { gameController = GetComponent<GameController>(); Time.timeScale = 1; rb = GetComponent<Rigidbody2D>(); objectHeight = transform.GetComponent<SpriteRenderer>().bounds.size.y / 2; } void Update() { if (Input.GetMouseButtonDown(0)) { rb.velocity = Vector2.up * velocity; } } }
Nice that you have got a problem. Try to describe your problem, so we can help you? Use Code Tags so we can read your code right? I Already see your typo, would love to answer after you update your Post
How to report your problem productively in the Unity3D forums: http://plbm.com/?p=220 If you post a code snippet, ALWAYS USE CODE TAGS: How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/ You may edit your post above.
The curly brace needs to come directly after the class definition above where you defined the variables. You currently have it after the variable definitions. Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerControls : MonoBehaviour { [Header("Game Controller Object for controlling the game")] public GameController gameController; [Header("Default Velocity")] public float velocity = 1; private Rigidbody2D rb; private float objectHeight; void Start() { gameController = GetComponent<GameController>(); Time.timeScale = 1; rb = GetComponent<Rigidbody2D>(); objectHeight = transform.GetComponent<SpriteRenderer>().bounds.size.y / 2; } void Update() { if (Input.GetMouseButtonDown(0)) { rb.velocity = Vector2.up * velocity; } } }