Search Unity

I have a problem to launch my script, it prevents the game from launching, help me correct it please

Discussion in 'Scripting' started by The_Big_Craftytb, Jul 25, 2019.

  1. The_Big_Craftytb

    The_Big_Craftytb

    Joined:
    Jul 25, 2019
    Posts:
    5
    I have a problem to launch my script, it prevents the game from launching, help me correct it please, it's for a FPS, unity 2019 1.10f1 cannot launch it i think. ;(
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class WeaponManagerG36C : MonoBehaviour {
    6.  
    7.     public float range = 500f;
    8.  
    9.     public int bulletsPerMag = 31; //Nombres de balles par chargeur ;)
    10.     public int bulletsLeft = 310; //Notre reserve de munition
    11.     public int currentBullets; //Les balles que l'on as
    12.  
    13.     public float fireRate = 0.1f;
    14.     float fireTimer;
    15.  
    16.     public Transform shootPoint;
    17.  
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.         currentBullets = bulletsPerMag;
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         if(Input.GetButton("Fire1"))
    28.         {
    29.             Fire();
    30.            
    31.         }
    32.  
    33.         if (fireTimer < fireRate)
    34.             fireTimer += Time.deltaTime;
    35.      }
    36.  
    37.  
    38.     private void Fire()
    39.     {
    40.         if (fireTimer < fireRate) return;
    41.  
    42.         RaycastHit hit;
    43.  
    44.         if(Physics.raycast(shootPoint.position, shootPoint.forward, out hit, range))
    45.         {
    46.             Debug.Log(hit.transform.name + " has been found!!!!!!");  
    47.         }
    48.  
    49.         fireTimer = 0.0f;
    50.     }
    51. }
    52.  
    game.PNG
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    This script looks correct. Explain your problem more detailed.
     
  3. The_Big_Craftytb

    The_Big_Craftytb

    Joined:
    Jul 25, 2019
    Posts:
    5
    when I put my script in my weapon, the shoot point option is supposed to appear in addition (to insert a 3d object). and then when I press the game the test does not start, how to do is to mark that there is an error in the console
     
  4. The_Big_Craftytb

    The_Big_Craftytb

    Joined:
    Jul 25, 2019
    Posts:
    5
    is the script compatible in my version?
     
  5. The_Big_Craftytb

    The_Big_Craftytb

    Joined:
    Jul 25, 2019
    Posts:
    5
    the console says its a problem with the word raycast
     
  6. The_Big_Craftytb

    The_Big_Craftytb

    Joined:
    Jul 25, 2019
    Posts:
    5
    i did it i do'nt write raycast in the right thing thanks