Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

need help with Error CS1002

Discussion in 'Scripting' started by brucehjoyner, Sep 17, 2021.

  1. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public void weapon
    5.  
    6. public class PlayerCombat : MonoBehaviour
    7. {
    8.     [SerializeField] GameObject[] _weapons;
    9.     [SerializeField] float _rateOfFire = 0.2f;
    10.     [SerializeField] GameObject _bullet;
    11.     [SerializeField] Transform _bulletSpawnPoint;
    12.  
    13.     private bool _isArmed = false;
    14.     private bool _isFiring = false;
    15.  
    16.    // Update is called once per frame
    17.     void Update()
    18.     {
    19.         //check to see if armed and if press left mouse button
    20.         if (Input.GetMouseButtonDown(0) && _isArmed)
    21.         {
    22.             //_isFiring set to true
    23.             _isFiring = true;
    24.             StartCoroutine(Firing());
    25.         }
    26.  
    27.         if (Input.GetMouseButtonUp(0) && _isArmed)
    28.         {
    29.             //_isFiring set to true
    30.             _isFiring = false;
    31.         }
    32.     }
    33.  
    34.     public void SetWeapon(weapon.WeaponType weaponType)
    35.     {
    36.         if (weaponType == weapon.weaponType.Pistol)
    37.         {
    38.             _Weapon[0].SetActive(true);
    39.             _isArmed = true;
    40.         }
    41.     }
    42.  
    43.     IEnumerator Firing ()
    44.     {
    45.         while (_isFiring)
    46.         {
    47.             //instantiate a bullet
    48.             GameObject bullet = Instantiate(_bullet, _bulletSpawnPoint.position, Quaternion.identify);
    49.             //fire the bullet in the direction
    50.             bullet.GetComponent<Rigibody>().velocity = transform.forward * 15000 * Time.deltaTime;
    51.             yield return new WaitForSeconds(_rateOfFire);
    52.         }
    53.     }
    54. }
    55.  
    I get error Assets\Scripts\Weapons\PlayerCombat.cs(4,19): error CS1002: ; expected
    Can someone tell me what it means? i cant understand
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Can you explain what line 4 above does?? I think it needs to be deleted.
     
  3. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    I put that there to try to make the error Assets\Scripts\Weapons\PlayerCombat.cs(33,27): error CS0246: The type or namespace name 'weapon' could not be found (are you missing a using directive or an assembly reference?) go away because it said missing namespace, and I thought that's what it meant
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    No it is missing that entire class, the
    Weapon
    class.

    Inside of
    Weapon
    is that other
    WeaponType
    type, which is likely an
    enum
    type in
    Weapon
    (could be a class?)
     
  5. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    so would something like this work?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerCombat : MonoBehaviour
    6. {
    7.     [SerializeField] GameObject[] _weapon;
    8.     [SerializeField] float _rateOfFire = 0.2f;
    9.     [SerializeField] GameObject _bullet;
    10.     [SerializeField] Transform _bulletSpawnPoint;
    11.  
    12.     private bool _isArmed = false;
    13.     private bool _isFiring = false;
    14.  
    15.    // Update is called once per frame
    16.     void Update()
    17.     {
    18.         //check to see if armed and if press left mouse button
    19.         if (Input.GetMouseButtonDown(0) && _isArmed)
    20.         {
    21.             //_isFiring set to true
    22.             _isFiring = true;
    23.             StartCoroutine(Firing());
    24.         }
    25.  
    26.         if (Input.GetMouseButtonUp(0) && _isArmed)
    27.         {
    28.             //_isFiring set to true
    29.             _isFiring = false;
    30.         }
    31.     }
    32.  
    33.     public void SetWeapon(weapon.WeaponType)
    34.     {
    35.         if (weaponType == weapon.weaponType.Pistol)
    36.         {
    37.             _Weapon[0].SetActive(true);
    38.             _isArmed = true;
    39.         }
    40.     }
    41.  
    42.     IEnumerator Firing ()
    43.     {
    44.         while (_isFiring)
    45.         {
    46.             //instantiate a bullet
    47.             GameObject bullet = Instantiate(_bullet, _bulletSpawnPoint.position, Quaternion.identify);
    48.             //fire the bullet in the direction
    49.             bullet.GetComponent<Rigibody>().velocity = transform.forward * 15000 * Time.deltaTime;
    50.             yield return new WaitForSeconds(_rateOfFire);
    51.         }
    52.     }
    53. }
    54.  
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Hey man, I'm not a compiler. Does it work?

    I'm gonna say it won't work until you give it the exact
    Weapon
    class it wants, or else engineer your own replacement for
    Weapon
    that will suit the needs of this code snippet.
     
  7. brucehjoyner

    brucehjoyner

    Joined:
    Mar 24, 2021
    Posts:
    12
    Yeah I don't know I gonna try a different script