我真的做基于在其中,每个级别,你必须在得分跟踪杆3个关卡水平的2D游戏。玩家必须达到最低的检查站,以便能够传递到一个新的水平,但如果他在达到第二和第三检查站将获得奖金。
我认为在使用滑块作为打分吧。我的问题是:
是否有存储Slider的条的特定值在Start方法和实例在该位置标记预制的方法吗?下面是一个例子:
我现在的逻辑是,我要,不知何故,得到我想要的价值,找到他的变换,但我可以`吨找到一种方法来编写这个,我不知道如何得到我想要的位置。
下面是一些图片来说明什么我真的想这样做:
我会得到滑块的宽度属性,然后除以sliderMax,其结果将是在所述滑块上的单一的%的宽度。那么你可以添加或本subract多拿到栏上一个百分比的地方。
例如:slider.x = 50 slider.width = 200;
increment = slider.width/100;
//这将导致两个,让你每增加1%的两个像素。
所以你的50%的位置将是:sliderx+(increment*50);
记住,这是所有的伪代码,旨在为您提供如何acheive你想要的结果的想法
我找到了解决办法!
基于我能够做到这一点的见解:
void SpawnCheckPoint() {
mySlider.maxValue = gameLevel[currentLevel].maxValue; //Set the slider's Max Value to the max value of the level.
float sliderMaxValue = mySlider.maxValue;
float sliderWidth = slider.GetComponent<RectTransform>().sizeDelta.x; //Get the width of the Slider.
float zeroValue = slider.transform.position.x - (sliderWidth / 2); //Get the leftmost corner of the slider.
//Loop to Instantiate the 3 checkpoints.
for (int i = 0; i < gameLevel[currentLevel].values.Length; i++) {
float valueToIncrement = (gameLevel[currentLevel].values[i] / sliderMaxValue); //Get the % of the checkpoint based on the max value of the level.
float newPos = (sliderWidth * valueToIncrement); //New position in screen
//Instantiate the object as a child of the Slider
GameObject checkpoint = Instantiate(checkPoint, new Vector3(zeroValue + newPos - xPadding, slider.transform.position.y - yPadding, slider.transform.position.z),
Quaternion.identity, GameObject.FindGameObjectWithTag("Slider").transform);
}
}
它可能不是做我想做什么是最好的方式,但它的工作就好了。
谢谢大家谁试图帮助我,你的见解是非常有用的。