Help pls my fps wont work

i fixed the semi colon inside of IF statement and got more errors. @Artmarab can you help again. I changed the float to a boolean because i thought it would fit more. I just started unity a couple days ago.

Here is code:

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

public class GunScript : MonoBehaviour
{
private Camera PlayerCamera;

public GameObject robot;

bool shoot = false;

void Start()
{
    PlayerCamera = Camera.main;
}

void Update()
{
    if (Input.GetAxis("Fire1"))
    {
        shoot = true;

    }

    if (shoot = true)
     {
            Ray gunray = new Ray(PlayerCamera.transform.position, PlayerCamera.transform.forward);

            if (Physics.Raycast(gunray, out RaycastHit hitInfo, robot))
            {
                Destroy(robot);
            }
       
    }
}

}

@Hehefunnyboi2 Step by step. I’ll tell you what is wrong and you’ll look for the correct way of doing it.

In your first IF statement you’re trying to get a true/false result (a bool) out from a property that returns a float value. Input.GetAxis returns a value that will be in the range -1…1 for keyboard and joystick input devices. You can read more about it in the documentation.

We usually use the GetAxis method for player movement and GetButtonDown for player action (like shooting). What you should be checking instead is IF the player pressed the key “Fire 1”.

In case you still want to use GetAxis you should compare the result to the *float * valuse assigned to your Fire1 button.

The content of the second IF statement should be moved to the first one. “If player presses the Fire button, cast a ray.” The use of the shoot bool here is redundant.

Physics.Raycast doesn’t get any Ray attribute. You need to feed it a RaycastHit attribute. You can read more about the correct way of raycasting in the documentation.

As a side note, this is not the correct way of using UnityAnswers. You should try to solve it by yourself first with the help of the errors that Unity prints in the Console window. If you can’t, you can post here a clear question stating exactly the kind of issue you have. Also try to not reffer to a unique person in the question because maybe a more seasoned developer might just skip it.