I’ve recently started Unity scripting and I need some help with my script. I’ve tried combining scripts to make my character able to move, jump, and pick-up items, thanks. At the “void start” part, it says void is “unexpected symbol” and in visual studio it has a line at the left showing purple/teal.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float Speed = 150.0f;
public Text countText;
public Text winText;
public AudioSource audio1;
private Rigidbody rb;
private int count;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
private void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal + 0.1f, 0.0f, moveVertical);
rb.AddForce(movement * Speed);
}
void OnTriggerEnter(Collider other)
{
audio1.Play();
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Score:" + count.ToString ();
if (count == 8)
{
winText.text = "You Win!";
}
}
}