Moving an object to another object code help
Hey I need some help with this sample Unity script, I know nothing about coding and just need an object to move over to another object, except I don't know what to add to this script:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform target;
public float speed;
void Update() {
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}
Any help would be appreciated thanks.
attach this script to the object you want to make it move & attach the second object you want to move To. to this script & give a value to the speed variable start from 1 & increase to move faster you don't need any coding it's all in unity editor .
"You don't need any coding, it's all in Unity Editor."
By Unity Editor, you mean Unity right? I'm still stuck on this aha I don't understand.
Thanks for the reply though.
Answer by ShazBang · Mar 05, 2016 at 04:42 AM
Alright so I figured it out myself and made a working script that moves an object to another object.
(Unfortunately I had to do it in java)
#pragma strict
var target: Transform;
var speed: float;
function Start () {
}
function Update () {
// The step size is equal to speed times frame time.
var step = speed * Time.deltaTime;
// Move our position a step closer to the target.
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
Your answer
Follow this Question
Related Questions
HOW TO MOVE A OBJECT TO ANOTHER OBJECT SMOOTHLY NOT INSTANTLY? 0 Answers
Saving old Position 1 Answer
Falling object respawner 1 Answer
Lerp on the every 3 * n cycle does some wierd thing. 0 Answers
How do I change the speed of this script 0 Answers