public class RollDice : MonoBehaviour
{
public int DiceNumber = 0; //dice number
public Text DiceText; //show dice number
public Transform _target1; //dice position
public Transform _target2; //dice position to move forward
public int _GruondIndex = 0; //The ground array index that will move the empty game objects
public float speed = 1f;
/*public Transform horseSpwanpoint;//horse is _target1 prefab
private void Awake()
{
Instantiate(_target1, horseSpwanpoint.position, horseSpwanpoint.rotation);
}
*/
private void Start()
{
_target2 = Tower.points[0]; // point is the location of the empty game objects in an array.
}
void Update()
{
_target1.position = Vector2.MoveTowards(_target1.position, _target2.position, speed * Time.deltaTime);
}
public void Dicegogo()
{
int ran = Random.Range(1, 6);
this.DiceNumber = ran;
DiceText.text = "Value : " + DiceNumber.ToString();
if (DiceNumber == 6)
{
_GruondIndex += 6;
_target2 = Tower.points[_GruondIndex];
}
else if (DiceNumber == 5)
{
_GruondIndex += 5;
_target2 = Tower.points[_GruondIndex];
}
else if (DiceNumber == 4)
{
_GruondIndex += 4;
_target2 = Tower.points[_GruondIndex];
}
else if (DiceNumber == 3)
{
_GruondIndex += 3;
_target2 = Tower.points[_GruondIndex];
}
else if (DiceNumber == 2)
{
_GruondIndex += 2;
_target2 = Tower.points[_GruondIndex];
}
else
{
_GruondIndex += 1;
_target2 = Tower.points[_GruondIndex];
}
Debug.Log(_target2);
}
}
This coding will work. But if i call awake method, it will not work.
I wonder if there is a rule that should not be used together, or if the coding is wrong.
Well you can of course have public Transform cloneTargets[ ] as a array, so you could have more those targets.
instantiate them in awake like cloneTargets[0] = (Transform) Instantiate(_target1, horseSpwanpoint.position, horseSpwanpoint.rotation); Or all of them with a loop.
and move them in update each one separately like clone Targets[0].Vector2.MoveTowards();
or all at one within a loop.
about that (Transform) Instantiate, i think you have to cast it so its the same type as the original, its the same as writing " as Transform" in the end.
i hope what i said isnt nonsense im not magister myself :- )
no , the reason it didnt work was because you were trying to drive a car in showroom, just by holding and turning a paper ad for that car. That is ,you were trying to move the actual prefab you have in your project in assets so to speak.not the gameobject in the game.
and that (Transform) or āas Transformā ā¦if you ,just for trying, were to delete that i think it will be an error or it would not work. Or it just might work i am not sure.but in general i think it has to be there : - )