how to fix error cs1061 Unity. Not what it seems like, very confusing

Viewed 35

When my prefab gets spawned into the game it forgets the game objects field's fill. if you dont get it (i found it hard to describe), then the following images explain it:

what it looks like when spawned in:image

what it is supposed to look like:image

So i have this code that fixed the problem for some different things but wont work on a button.

This script is attached to the button:

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

public class ShootButton : MonoBehaviour
{
public static ShootButton Instance { get; private set; }
void Awake()
{
    if (Instance != null && Instance != this)
    {
        Destroy(this);
    }
    else
    {
        Instance = this;
    }
}
}

And this script is attached to the player:

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

public class Weapon : MonoBehaviour
{
public Transform firePoint;
public GameObject bulletPrefab;
public Button shootButton;

void OnEnable()
{
    if (shootButton == null)
    {
        shootButton = ShootButton.Instance;
    }
}

void Start()
{
    shootButton.onClick.AddListener(shootButtonTrue);
}

void shootButtonTrue()
{
    Shoot();
}

void Shoot()
{
    Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
}
}

but when i try that out i get this error:

Assets\stuff\Scripts\Weapon.cs(16,27): error CS0029: Cannot implicitly convert type 'ShootButton' to 'UnityEngine.UI.Button'

If you need any other information or code then please ask. I am a noob at unity i only know a little bit so I wont understand complicated answers Thanks in advance!

0 Answers
Related