unity script to make object move code example
Example 1: how to move a gameobject to another object
public GameObject Bullet
public GameObject Cannon
void Start()
{
(Bullet) = GameObject.Find("Bullet");
(Cannon) = GameObject.Find("Cannon");
Bullet.transform.position = Cannon.transform.position;
}
Example 2: how to move towards an object unity
Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)
Example 3: hot to move pobject unity
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime);
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
}