Consider the following code snippet below:
class Mover : MonoBehaviour
{
Vector3 target;
float speed;
void Update()
{
}
}
Finish this code so the GameObject containing this script moves with constant speed towards target, and stop moving once it reaches 1.0, or less, units of distance?
Submitted by: Muhammadclass Mover : MonoBehaviour
{
Vector3 target;
float speed;
void Update()
{
float distance = Vector3.Distance(target,transform.position);
// will only move while the distance is bigger than 1.0 units
if(distance > 1.0f)
{
Vector3 dir = target - transform.position;
dir.Normalize(); // normalization is obligatory
transform.position += dir * speed * Time.deltaTime; // using deltaTime and speed is obligatory
}
}
}
Submitted by: Muhammad
{
Vector3 target;
float speed;
void Update()
{
float distance = Vector3.Distance(target,transform.position);
// will only move while the distance is bigger than 1.0 units
if(distance > 1.0f)
{
Vector3 dir = target - transform.position;
dir.Normalize(); // normalization is obligatory
transform.position += dir * speed * Time.deltaTime; // using deltaTime and speed is obligatory
}
}
}
Submitted by: Muhammad
Read Online Unity 3D Developer Job Interview Questions And Answers
Top Unity 3D Developer Questions
☺ | Explain what is Prefabs in Unity 3D? |
☺ | List out some best practices for Unity 3D? |
☺ | What's the best game of all time and why? |
☺ | Mention what is the function of Inspector in Unity 3D? |
☺ | List out the pros and cons of Unity 3D? |
Top Application Program Categories
☺ | AutoCAD Interview Questions. |
☺ | Microsoft Office Interview Questions. |
☺ | Microsoft Outlook Interview Questions. |
☺ | Microsoft Excel Interview Questions. |
☺ | WPF Interview Questions. |