Also check This post
Unity Amazing free assets              Windridge City
Top 3 game made with unity          Made with unity
Unity 3d lights on/off with UI       Lights on/off
Cube move with UI button steps
- First we need 3d plan and one cube.
 - Add rigid-body component to cube
 - Add this script to cube
 
using UnityEngine;
using System.Collections;
public class CubeMove : MonoBehaviour {
    public float speed;
    private Rigidbody rb;
    void Start ()
    {
        rb = GetComponent<Rigidbody>();
    }
    void FixedUpdate ()
    {
       // float moveHorizontal = Input.GetAxis ("Horizontal");
       // float moveVertical = Input.GetAxis ("Vertical");
       // Vector3 movement = new Vector3 (5f, 0.0f, 2f);
    }
public void Right() 
{
Vector3 movement = new Vector3 (10f, 0.0f, 0.0f);
rb.AddForce (movement * speed);
}
public void Left() 
{
Vector3 movement = new Vector3 (-10f, 0.0f, 0.0f);
rb.AddForce (movement * speed);
}
public void Farward() 
{
Vector3 movement = new Vector3 (0.0f, 0.0f, 10f);
rb.AddForce (movement * speed);
}
public void Back() 
{
Vector3 movement = new Vector3 (0.0f, 0.0f, -10f);
rb.AddForce (movement * speed);
}
}
/////////////////////////////////////////////////////////............/////////////////////////////////////////////////////////////
4.Add four UI buttons to move cube like forward,back,left and right move.like this image
 . 5.Add public functions to UI buttons like "public void Right()" function to right move button and same other functions.
  6.Test and play your cube. 


0 Comments