how to move a gameobject code example
Example 1: how to move a gameobject
public static int movespeed = 3;
public Vector3 userDirection = Vector3.down;
void Update()
{
transform.Translate(userDirection * movespeed * Time.deltaTime);
}
Example 2: how to move a gameobject to another object
//Attach this to the oject you want to move
public GameObject Bullet
public GameObject Cannon
void Start()
{
(Bullet) = GameObject.Find("Bullet"); //These are to find the object to move to
(Cannon) = GameObject.Find("Cannon");
Bullet.transform.position = Cannon.transform.position; //this is to move the object
}
Example 3: moving an object in unity
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Update()
{
// Move the object forward along its z axis 1 unit/second.
transform.Translate(Vector3.forward * Time.deltaTime);
// Move the object upward in world space 1 unit/second.
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
}