Инспектор (для шара-спрайта) Попытка добавить скрипт Ball в "Ball" Я создаю 2D-игру BlockBreaker и всякий раз, когда пытаюсь подключить скрипт к спрайту выдает ошибку: «Невозможно добавить поведение скрипта VisualContainerAsset. Скрипт должен быть производным от MonoBehaviour».
Всего у меня есть 6 сценариев, и когда я пытаюсь прикрепить один к спрайту, каждый из них выдает мне ту же ошибку. Может кто-нибудь сказать мне, почему?
СКРИНШОТ ОШИБКИ
Это сценарий мяча:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour {
public Paddle paddle;
bool hasStarted = false;
Vector3 paddleToBallVector;
void Start () {
paddleToBallVector = this.transform.position - paddle.transform.position;
}
// Update is called once per frame
void Update () {
if(hasStarted == false)
{
this.transform.position = paddle.transform.position + paddleToBallVector;
if (Input.GetMouseButtonDown(0))
{
hasStarted = true;
this.GetComponent<Rigidbody2D>().velocity = new
Vector2(Random.Range(-1f, 3f), 10f); //This is for the ball to bounce randomly
}
}
}
void OnCollisionEnter2D(Collision2D myColl)
{
if (myColl.gameObject.name == "Rightborder" || myColl.gameObject.name == "Leftborder") //If the ball hits either the left border or the right border
{
this.GetComponent<Rigidbody2D>().velocity += new Vector2(0f, 1f); //When the ball hits one of the borders, the speed will not be reduced
}
}
}