AssetsScriptsGameContoller.cs(29,73): error CS1061: ‘GameObject[]’ does not contain a definition for ‘ToList’ and no accessible extension method ‘ToList’ accepting a first argument of type ‘GameObject[]’ could be found (are you missing a using directive or an assembly reference?) Полная ошибка.
Не могу понять в чем проблема, почему ему не нравиться ToList()?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameContoller : MonoBehaviour
{
public enum GameState { START, PLAY, LOSE, GAME_OVER};
public event System.Action<GameState> OnStateChanged;
private GameState state;
[SerializeField] private Transform levelRegion = null;
[SerializeField] private Level LevelPrefab = null;
[SerializeField] private List<Color> colors = new List<Color>();
private List<Level> levels = new List<Level>();
private List <GameObject> ObstaclePrefabs ;
public GameState State { get => state; set { state = value; OnStateChanged?.Invoke(state);} }
public static GameContoller Instance;
[SerializeField] private Transform spawnRegion;
private void Awake()
{
Instance = this;
}
private void Start()
{
ObstaclePrefabs = Resources.LoadAll<GameObject>(«GroupObstacles»).ToList();
for (int i=0; i<2;i++)
{
levels.Add(SpawnNewLevel1());
}
ResetLevels();
}
private void ResetLevels()
{
levels[0].AnchoredPosition = new Vector3(0, -levels[0].Size.y / 2);
for ( int i = 1; i < levels.Count; i ++)
{
levels[i].AnchoredPosition = new Vector3(0, levels[i — 1].AnchoredPosition.y + levels[ i- 1].Size.y);
}
}
private Level SpawnNewLevel1()
{
Level level = Instantiate(LevelPrefab, Vector3.zero, Quaternion.identity, levelRegion);
level.AnchoredPosition =Vector3.zero;
level.BackColor = colors[UnityEngine.Random.Range(0, colors.Count)];
level.Size = new Vector2 (levelRegion.parent.GetComponent<RectTransform>().sizeDelta.x, levelRegion.parent.GetComponent<RectTransform>().sizeDelta.y * 2 );
//level.Size = new Vector2(levelRegion.parent.GetComponent<RectTransform>().sizeDelta.x, levelRegion.parent.GetComponent<RectTransform>().sizeDelta.y * 2 );
return level;
}
public void StartGame()
{
State = GameState.PLAY;
SpawnObstacle(ObstaclePrefabs[UnityEngine.Random.Range(0, ObstaclePrefabs.Count)], spawnRegion);
}
private void SpawnObstacle(GameObject gameObject, Transform spawnRegion)
{
Instantiate(gameObject, spawnRegion.transform.position, Quaternion.identity, spawnRegion);
}
}
error CS1061: Type `UnityEngine.UI.Image’ does not contain a definition for `enable’ and no extension method `enable’ of type `UnityEngine.UI.Image’ could be found. Are you missing an assembly reference?
Код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthSystem : MonoBehaviour {
public int health;
public int numberOfLives;
public Image[] lives;
public Sprite fullLive;
public Sprite emptyLive;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
for (int i = 0; i < lives.Length; i++)
{
if (i < numberOfLives)
{
lives[i].enable = true;
}
else
{
lives[i].enable = false;
}
}
}
}
-
Вопрос заданболее трёх лет назад
-
4432 просмотра
Компилятор тебе четко говорит, что у Image, нет свойства enable. Чтобы это проверить, идешь на офф сайт и ищешь класс Image. Находим инфу. Убеждаемся, что компилятор не соврал и изменяем на правильное свойство
Properties enabled
Как я понял у тебя есть на сцене много Image в канвасе, и тебе нужно их включать и выключать. Если я прав, то сделай вот что: обьяви не public Image[] lives; а public GameObject[] lives; так как на сцене у тебя обьекты GameObject, а Image — это компонент обьекта. И еще используй не enabled, а lives[i].SetActive(true/false);
Пригласить эксперта
-
Показать ещё
Загружается…
07 июн. 2023, в 01:32
5000 руб./за проект
07 июн. 2023, в 00:54
15000 руб./за проект
07 июн. 2023, в 00:51
13000 руб./за проект
Минуточку внимания
I’m running into the quite simple aforementioned error. I thought I’d fix it quite quickly, but even after quite some searching, I can’t for the life of me figure out what the problem is. I Have the following Interface:
public interface ITemperatureEmitter
{
float CurrentTemperatureAddon { get; }
}
I implement this in two other (empty for now) Interfaces:
public interface ITemperatureEmitterEnvironment : ITemperatureEmitter
public interface ITemperatureEmitterSphere : ITemperatureEmitter
Subsequently I use these three interfaces in the following class:
using System.Collections.Generic;
using UnityEngine;
public class TemperatureReceiver : MonoBehaviour, ITemperatureReceiver
{
public float PerceivedTemperature;
// Serialized for debug purposes
[SerializeField] private List<ITemperatureEmitterSphere> temperatureEmitterSpheres;
[SerializeField] private List<ITemperatureEmitterEnvironment> temperatureEmitterEnvironments;
[SerializeField] private float environmentTemperature;
[SerializeField] private float temperatureToModifyBy;
[SerializeField] private float currentTemperatureAddon;
[SerializeField] private float appliedTemperatureAddon;
[SerializeField] private float totalTemperatureAddon;
private void Update()
{
UpdatePerceivedTemperature();
}
private void OnTriggerEnter(Collider other)
{
if (other.GetComponent<ITemperatureEmitterSphere>() != null)
{
temperatureEmitterSpheres.Add(other.GetComponent<ITemperatureEmitterSphere>());
}
else if (other.GetComponent<ITemperatureEmitterEnvironment>() != null)
{
temperatureEmitterEnvironments.Add(other.GetComponent<ITemperatureEmitterEnvironment>());
}
}
private void OnTriggerExit(Collider other)
{
if (other.GetComponent<ITemperatureEmitterSphere>() != null)
{
temperatureEmitterSpheres.Remove(other.GetComponent<ITemperatureEmitterSphere>());
}
else if (other.GetComponent<ITemperatureEmitterEnvironment>() != null)
{
temperatureEmitterEnvironments.Remove(other.GetComponent<ITemperatureEmitterEnvironment>());
}
}
private void UpdatePerceivedTemperature()
{
ModifyPerceivedTemperature(temperatureEmitterSpheres);
ModifyPerceivedTemperature(temperatureEmitterEnvironments);
}
private void ModifyPerceivedTemperature<ITemperatureEmitter>(List<ITemperatureEmitter> list)
{
if (list.Count > 0)
{
foreach (var item in list)
{
currentTemperatureAddon += item.CurrentTemperatureAddon;
}
currentTemperatureAddon = currentTemperatureAddon / list.Count;
appliedTemperatureAddon = PerceivedTemperature;
temperatureToModifyBy = currentTemperatureAddon = appliedTemperatureAddon;
PerceivedTemperature += temperatureToModifyBy;
}
}
}
Now the item.CurrentTemperatureAddon
in the ModifyPercievedTemperature
method emits «error CS1061: Type ITemperatureEmitter
does not contain a definition for CurrentTemperatureAddon
and no extension method CurrentTemperatureAddon
of type ITemperatureEmitter
could be found. Are you missing an assembly reference?«
ITemperatureEmitter
quite literally does contain a definition for CurrentTemperatureAddonm
… Anyone has an idea what’s happening here?
I cannot explain why this is not working. So, I downloaded Git from the link. Is there an extra option after? After I downloaded and installed it I went to the package handler option. I then entered the link into the search by ULR option. I got the same Error saying Git was not Installed, but it is installed, so I do not know If I am missing a option. I went into the Package handler and installed the json file and it actually installed. It says that 2D Tilemap Extras has been installed. Now I keep getting a error though in the bottom. It is the
C:UserssabolDesktop123452d-extras-masterEditorTilesRuleTileRuleTileEditor.cs(347,82): error CS1061: ‘ReorderableList’ does not contain a definition for ‘IsSelected’ and no accessible extension method ‘IsSelected’ accepting a first argument of type ‘ReorderableList’ could be found (are you missing a using directive or an assembly reference?)
C:UserssabolDesktop123452d-extras-masterEditorTilesRuleTileRuleTileEditor.cs(341,22): error CS1061: ‘ReorderableList’ does not contain a definition for ‘IsSelected’ and no accessible extension method ‘IsSelected’ accepting a first argument of type ‘ReorderableList’ could be found (are you missing a using directive or an assembly reference?)
C:UserssabolDesktop123452d-extras-masterEditorTilesRuleTileRuleTileEditor.cs(327,26): error CS1061: ‘ReorderableList’ does not contain a definition for ‘IsSelected’ and no accessible extension method ‘IsSelected’ accepting a first argument of type ‘ReorderableList’ could be found (are you missing a using directive or an assembly reference?)
Baltick 0 / 0 / 0 Регистрация: 14.08.2021 Сообщений: 1 |
||||
1 |
||||
14.08.2021, 21:12. Показов 2188. Ответов 2 Метки unity, unity3d (Все метки)
AssetsPlayerMovement.cs(20,16): error CS1061: ‘GameManager’ does not contain a definition for ‘EndGame’ and no accessible extension method ‘EndGame’ accepting a first argument of type ‘GameManager’ could be found (are you missing a using directive or an assembly reference?) AssetsPlayerMovement.cs(49,16): error CS1061: ‘GameManager’ does not contain a definition for ‘EndGame’ and no accessible extension method ‘EndGame’ accepting a first argument of type ‘GameManager’ could be found (are you missing a using directive or an assembly reference?) Вот мой код
0 |
563 / 363 / 208 Регистрация: 18.10.2019 Сообщений: 1,231 |
|
14.08.2021, 21:40 |
2 |
Baltick, тебе ошибка прямо говорит, что в классе GameManager нет метода EndGame. Значит либо его там и правда вовсе нет, либо ты его по другому назвал, а пытаешься вызвать по несуществующему названию.
0 |
1 / 1 / 0 Регистрация: 25.03.2021 Сообщений: 15 |
|
14.08.2021, 22:07 |
3 |
Чет очень знакомый код, это с какого-то урока?
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
14.08.2021, 22:07 |
3 |