void Update()
{
transform.position = new Vector3(1, 2, 3); // Moves the object to (1,2,3)
}
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * 5);
}
InvokeRepeating() is a built-in Unity function that repeatedly calls a method at fixed time intervals.
InvokeRepeating("MethodName", initialDelay, repeatRate);
// Example
using UnityEngine;
public class AutoShooter : MonoBehaviour
{
public GameObject bulletPrefab;
void Start()
{
InvokeRepeating("Shoot", 1f, 0.5f); // Start shooting after 1s, then every 0.5s
}
void Shoot()
{
Instantiate(bulletPrefab, transform.position, Quaternion.identity);
}
}
Instantiate() is a Unity method used to create copies (or clones) of GameObjects or prefabs at runtime.
Instantiate(original, position, rotation);
// Example
public GameObject bulletPrefab; // Bullet prefab to instantiate
void Shoot()
{
Instantiate(bulletPrefab, transform.position, Quaternion.identity); // Spawn bullet at Launcher's position
}
Destroy() is a Unity method used to remove or delete a GameObject, Component, or Asset from the scene, usually during runtime.
Destroy(object);
// Example
public GameObject enemy;
void DestroyEnemy()
{
Destroy(enemy); // Destroys the 'enemy' GameObject
}