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;
}
}
}
}
-
Вопрос заданболее трёх лет назад
-
4423 просмотра
Компилятор тебе четко говорит, что у Image, нет свойства enable. Чтобы это проверить, идешь на офф сайт и ищешь класс Image. Находим инфу. Убеждаемся, что компилятор не соврал и изменяем на правильное свойство
Properties enabled
Как я понял у тебя есть на сцене много Image в канвасе, и тебе нужно их включать и выключать. Если я прав, то сделай вот что: обьяви не public Image[] lives; а public GameObject[] lives; так как на сцене у тебя обьекты GameObject, а Image — это компонент обьекта. И еще используй не enabled, а lives[i].SetActive(true/false);
Пригласить эксперта
-
Показать ещё
Загружается…
04 июн. 2023, в 01:35
1500 руб./за проект
04 июн. 2023, в 01:25
40000 руб./за проект
03 июн. 2023, в 23:42
1500 руб./за проект
Минуточку внимания
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?)
I am new to .NET visual studio, building windows Form Application.
I had the following error described below, when trying to build a solution. I am not sure if it has to do with something related to the file ‘SuperAdventure.SuperAdventure’ or a control that was not specified.
‘SuperAdventure.SuperAdventure’ does not contain a definition for ‘label5_Click‘ and no extension method ‘label5_Click’ accepting a first argument of type ‘SuperAdventure.SuperAdventure’ could be found (are you missing a using directive or an assembly reference?)
This is the error code with the error showing a red squiggly/line under the code in the marked line.
// lblExperience
//
this.lblExperience.AutoSize = true;
this.lblExperience.Location = new System.Drawing.Point(110, 73);
this.lblExperience.Name = "lblExperience";
this.lblExperience.Size = new System.Drawing.Size(35, 13);
this.lblExperience.TabIndex = 6;
this.lblExperience.Text = "label7";
this.lblExperience.Click += new System.EventHandler(this.label5_Click); // <-- squiggly line here
and on the output it gives this:
-
1>—— Build started: Project: Engine, Configuration: Release Any
CPU —— -
1> Engine -> C:UsersAdminDocumentsVisual Studio
2013ProjectsSuperAdventureEnginebinReleaseEngine.dll -
2>——
Build started: Project: SuperAdventure, Configuration: Release Any
CPU —— -
2>c:UsersAdminDocumentsVisual Studio
2013ProjectsSuperAdventure.Designer.cs(119,70,119,82): error
CS1061: ‘SuperAdventure.SuperAdventure’ does not contain a
definition for ‘label5_Click’ and no extension method
‘label5_Click’ accepting a first argument of type
‘SuperAdventure.SuperAdventure’ could be found (are you missing a
using directive or an assembly reference?) ========== Build: 1
succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please let me know if I need to provided any more information.
PS: I am a beginner trying to learn some C# by building a RPG game as an exercise.