using UnityEngine;
using System.Collections;
namespace FairyMental
{
public class CubeRandomMovement : MonoBehaviour
{
public Transform myCube;
public int randomNumber;
public float randomDirection;
public AnimationCurve myCurve;
private bool isMoving = false;
private int ct = 0;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
randomNumber = Random.RandomRange(1, 4);
randomDirection = myCurve.Evaluate(Random.RandomRange(0.0f, 1.0f));
Debug.Log(randomDirection);
if (!isMoving)
{
InvokeRepeating("MoveObject", 0, 0.1f);
isMoving = true;
ct = 0;
}
float[] array = { 1, 2, 3, 4, 5 };
}
void MoveObject()
{
float posX = 0.0f;
float posZ = 0.0f;
if (randomDirection < 0.25f )
{
posX += 0.5f;
}
else if ( randomDirection < 0.5f)
{
posX -= 0.5f;
}
else if (randomDirection < 0.75f)
{
posZ += 0.5f;
}
else
{
posZ -= 0.5f;
}
Vector3 pos = new Vector3(posX, 0, posZ);
myCube.position += pos;
ct++;
if (ct >= randomNumber)
{
CancelInvoke("MoveObject");
isMoving = false;
ct = -1;
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.