[Unity] I saw how to use Slider and how to get values in real time and wrote the code.
The Slider does not contain a value definition and could not find an accessible extended method value to accept the first argument for the type Slider. I wrote in visualtudio to make sure that there are not enough using directives or assembly references.
The same goes for maxvalue
What should I do?
using System.Collections;
using System.Collections.General;
using UnityEngine;
using UnityEngine.UI;
public class slider —MonoBehavior
{
Slider hpSlider;
// Use this for initialization
void Start()
{
hpSlider=GetComponent<Slider>();
float maxHp = 200f;
float nowHp = 100f;
// Set slider maximum
hpSlider.maxValue=maxHp;
// Setting the current value of the slider
hpSlider.value = nowHp;
}
// Update is called once per frame
void Update()
{
}
}
[Response to the revised question article]
I think the content is similar to the following article.
Reflected in real time on slider of unity
The class name you are trying to create in the source code is Slider
, which conflicts with the abbreviation Slider
of UnityEngine.UI.Slider
that you are really trying to use.
Change the class name (and the filename it contains) from Slider
.
Also, it seems that the class name and the file name in the front part of .cs must be the same, including upper case letters.
When you ask questions, be sure to provide as much detail as possible (for privacy and security reasons) as possible, including error messages.
[Supplement]
By the way, this article seems to be newer, so it may not change, but why don't you change the reference source to this one?
Unity: Displaying the slider like an HP bar
Using Slider to Express Boss Character HP BarNote:
Delete the original answer.
Therefore, the comments may seem strange, but I'm sorry.
https://teratail.com/questions/255001
Someone else told me
Because the class name and file name were Slider.
Changing the class name and file name to a different name resolved
© 2024 OneMinuteCode. All rights reserved.