The question is answered, right answer was accepted
If two Vector2 are same
I need to get True/False, if first Vector2 is equal to second Vector2.
Answer by Gruffy · Mar 23, 2014 at 05:29 PM
Hey bud try this out.
You need a gameobject in your scene that will move to another gameobject, so have two game objects that your camera can see in the scene. The add this script to one of them and then add the other gameobject`s vector coords in the public slot in the inspector showing x y positions. Press start and you should see the first gameobject (with this script atttached to it) move along to the other one you gave vector coords for and when it arrives itll stop (itll probably happen quite fast unless you put some distance between the two gameobjects) Before you start the Play button in the eidtor, get your console window up and see that you have a debug happeneing saying "false" over and over again. when it has reached the vector coords specified in your script for vect2, it will say "true" and a text statement afterwards. Hope this helps dude. Gruffy
using UnityEngine;
using System.Collections.Generic;
public class MyClass : MonoBehaviour
{
public bool myBool = false;
private Transform vect1; //set in inspector
public Transform vect2; // set in inspector, this is
void Start()
{
vect1 = transform.position;
}
void Update()
{
//move this transform towards the vect2 position you gave in inspector panel for this script
transform.Translate(vect2 * Time.deltaTime);
//if vect 1 not same as vect2
if(vect1.position != vect2.position )
{
myBool = false;
Debug.Log(myBool);
}
else
{
myBool = true;
Debug.Log(myBool + "You have reached your destination");
}
}
}
Follow this Question
Related Questions
Animation changes constantly reset themselves. 1 Answer
iscometric grid panning 0 Answers
Get angle between a position and facing direction 0 Answers
Trying to Generate Different Random Values for Position of Game Object Instances [C#] 1 Answer
How to move a 2D object toward the position it is pointing to? 0 Answers