У меня есть скрипт, который вращает несколько кубиков вокруг, чтобы имитировать игровой автомат.Я обновил размер преобразований с 45 пикселей на размер до 40. Сценарий по-прежнему ведет себя так, как если бы они были 45 на 45. Я не могу представить, почему это происходит.
Все преобразователи имеют 40 пикселей в инспекторе,Преобразования движутся на 45 пикселей как их скорость.Я не знаю почему.Я пробовал Space.Self, то же самое.При вызове функции сброса преобразователи распределяются даже на прежние места.
Есть идеи?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reel : MonoBehaviour
{
//This Variable Will Be Changed By The "Slots" Class To Control When The Reel Spins
public bool spin;
//Speed That Reel Will Spin
float speed;
public int updates = 0;
// Use this for initialization
void Start()
{
spin = false;
speed = 0.2f;
}
// Update is called once per frame
void Update()
{
if (spin)
{
foreach (Transform image in transform)//This Targets All Children Objects Of The Main Parent Object fghjfgh smooth Time.smoothDeltaTime *
{
//Direction And Speed Of Movement
image.transform.Translate(Vector2.right * speed, Space.World);
//Once The Image Moves Below A Certain Point, Reset Its Position To The Top
if (image.transform.position.x >= +3) { image.transform.position = new Vector2(image.transform.position.x -6, image.transform.position.y); }
}
updates = updates + 1;
}
}
//Once The Reel Finishes Spinning The Images Will Be Placed In A Random Position
public void RandomPosition()
{
List<int> parts = new List<int>();
//Add All Of The Values For The Original Y Postions
parts.Add(2);
parts.Add(1);
parts.Add(0);
parts.Add(-1);
parts.Add(-2);
parts.Add(-3);
foreach (Transform image in transform)
{
int rand = Random.Range(0, parts.Count);
//The "transform.parent.GetComponent<RectTransform>().transform.position.y" Allows It To Adjust To The Canvas Y Position)
image.transform.position = new Vector2(parts[rand] + transform.parent.GetComponent<RectTransform>().transform.position.x, image.transform.position.y);
parts.RemoveAt(rand);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slots : MonoBehaviour
{
public Reel[] reel;
bool startSpin;
// Use this for initialization
void Start()
{
startSpin = false;
}
// Update is called once per frame
void Update()
{
if (!startSpin)//Prevents Interference If The Reels Are Still Spinning
{
if (Input.GetKeyDown(KeyCode.K))//The Input That Starts The Slot Machine
{
startSpin = true;
StartCoroutine(Spinning());
}
if (Input.GetKeyDown(KeyCode.H))//The Input That Starts The Slot Machine
{
reel[0].RandomPosition();
}
}
}
IEnumerator Spinning()
{
foreach (Reel spinner in reel)
{
//Tells Each Reel To Start Spnning
spinner.spin = true;
}
for (int i = 0; i < reel.Length; i++)
{
//Allow The Reels To Spin For A Random Amout Of Time Then Stop Them
//yield return new WaitForSeconds(Random.Range(1, 3));
while (reel[0].updates != 100)
{
yield return null;
}
reel[0].spin = false;
reel[0].updates = 0;
}
//Allows The Machine To Be Started Again
startSpin = false;
}
}