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 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’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?
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Clicker : MonoBehaviour
{
public static Clicker Instanse;
public float Money
{
get => PlayerPrefs.GetFloat(«Money», 0);
private set => PlayerPrefs.SetFloat(«Money», value);
}
[SerializeField]
private TextMeshProUGUI money;
[SerializeField]
private List<AmplifierPref> amplifierPrefs;
private List<DamageAmplifier> amplifiers;
private void Awake()
{
Instanse = this;
}
void Start()
{
amplifiers = new List<DamageAmplifier>()
{
new DamageAmplifier(DamageAmplifier.AmplifierType.PLUS_CLICK_DAMAGE, 0, false, 2, 1.5F, 100, 75),
new DamageAmplifier(DamageAmplifier.AmplifierType.CLICK_CRIT, 100, false, 2, 2f, 200, 100, 25),
new DamageAmplifier(DamageAmplifier.AmplifierType.PASSIVE_DAMAGE, 0, true, 2, 1.25f, 125, 50),
};
for (int i = 0; i < amplifierPrefs.Count; i++)
amplifierPrefs[i].SetData(amplifiers[i]);
StartCoroutine(PassiveDamageDealer());
UpdateUI();
}
private IEnumerator PassiveDamageDealer()
{
while (true)
{
yield return new WaitForSeconds(1);
DamageTarget(GetPassiveDamage());
}
}
public void Click()
{
DamageTarget(GetClickDamage());
}
private void DamageTarget(float damage)
{
AddMoney(damage);
}
private float GetClickDamage()
{
float damage = 1;
var sortedAmplifiers = amplifiers.FindAll(x => !x.IsPassive);
sortedAmplifiers.Sort((x, y) => x.Priority.CompareTo(y.Priority));
foreach (var amplifier in sortedAmplifiers)
damage = amplifier.CalculateDamage(damage);
return damage;
}
private float GetPassiveDamage()
{
float damage = 0;
var sortedAmplifiers = amplifiers.FindAll(x => x.IsPassive);
sortedAmplifiers.Sort((x, y) => x.Priority.CompareTo(y.Priority));
foreach (var amplifier in sortedAmplifiers)
damage = amplifier.CalculateDamage(damage);
return damage;
}
public void UpdateUI()
{
money.text = «$» + (int)Money;
}
public void AddMoney(float value)
{
Money += value;
UpdateUI();
foreach (var pref in amplifierPrefs)
pref.UpdateUI();
}
}
-
#2
Why exactly do you think that the Vector2
class does have a GetAxisRaw
method? I’ve never used Unity but, as far as I can tell, the error message is spot on and the only GetAxisRaw
method is a static
member of the Input
class. Example 5 here uses both the Vector2
class and the Input.GetAxisRaw
method. If I could find that information, which I did by simply searching the web for «unity getaxisraw», then you should have been able to as well.
-
#3
Hi guys, New to coding trying to create player movement and these errors are showing up in unity —
AssetsScriptMovement.cs(16,26): error CS1061: ‘Vector2’ does not contain a definition for ‘GetAxisRaw’ and no accessible extension method ‘GetAxisRaw’ accepting a first argument of type ‘Vector2’ could be found (are you missing a using directive or an assembly reference?)
AssetsScriptMovement.cs(17,26): error CS1061: ‘Vector2’ does not contain a definition for ‘GetAxisRaw’ and no accessible extension method ‘GetAxisRaw’ accepting a first argument of type ‘Vector2’ could be found (are you missing a using directive or an assembly reference?)
How can I fix this?using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { public float moveSpeed; private bool isMoving; private Vector2 input; private void Update () { if (!isMoving) { input.x = input.GetAxisRaw("Horizontal"); input.y = input.GetAxisRaw("Vertical"); if (input != Vector2.zero) { var targetPos = transform.position; targetPos.x += input.x; targetPos.y += input.y; StartCoroutine(Move(targetPos)); } } } IEnumerator Move(Vector3 targetPos) { isMoving = true; while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon) { transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime); yield return null; } transform.position = targetPos; } }
Change the input.GetAxisRaw to Input.GetAxisRaw