Beginner question, strange error that makes no sense

Hello,
So I’m making a side scroller, but it’s been over a year since I’ve coded anything.
I’m checking the code from a tutorial (brackeys)

I’m at the pulling my hair out phaze and this makes no sense at all.

here is a copy of the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnBullet : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
public Transform FirePoint;
public GameObject BulletPrefab;
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(“f”))
{
Debug.Log(“Fire!”);
fireweapon();
}
}
void fireweapon()
{
//Bullet Logic
instantiate(BulletPrefab, FirePoint.position, FirePoint.rotation);
}
}


Please post your code with Code Tags in the future for better readability.

You cannot have variables with access modifiers such as “public” inside of a method, as you do in Start().

Also, those variables are used elsewhere in the script, so most likely you want to just pull those variables out of the method, so they are instance variables.

Inside fireweapon(), you have simply misspelled “instantiate”, which should be “Instantiate”.

I’ve done that, fixed the compile errors,
Thank you so much!

I’ll be sure to add in future

1 Like

EXCELLENT! And I have some more good news for you:

How to understand compiler and other errors and even fix them yourself:

https://discussions.unity.com/t/824586/8