Search Unity

Question how do i get my script working

Discussion in 'Getting Started' started by Rileyjoe, Aug 3, 2022.

  1. Rileyjoe

    Rileyjoe

    Joined:
    Aug 3, 2022
    Posts:
    2
    Assets\pistol\color\Gun.cs(13,43): error CS1003: Syntax error, ',' expected
    this is the error i recieved for my script i got from a video heres the scrip

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

    public class Gun : MonoBehaviour
    {
    public Transform bulletSpawnPoint;
    public GameObject bulletPrefab;
    public float bulletSpeed = 10;

    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Left Mouse Key))
    {
    var bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
    bullet.GetComponent<Rigidbody>().velocity = bulletSpawnPoint.forward * bulletSpeed;
    }
    }
    }



    i have underlines where it says the problem is please help
     
  2. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    First, please use code tags when posting code examples, as I do below. Makes it much easier for people to help.

    From the Unity Docs, here is how to sense the left mouse click.

    Code (CSharp):
    1. public class Example : MonoBehaviour
    2. {
    3.     void Update()
    4.     {
    5.         //Detect if the left mouse button is pressed
    6.         if (Input.GetKey(KeyCode.Mouse0))
    7.         {
    8.             Debug.Log("Mouse 0 ");
    9.         }
    10.     }
    11. }