How to get a vector 3 to vector 2 - c#
I need help getting a Vector 3 to a Vector 2 or another method on using a vector 2 and 3 in a if statement
All the documentation says is:
Vector2.Vector2 Parameters Description Converts a Vector3 to a Vector2. Vector3s can be implicitly converted to Vector2 (z is discarded).
^ This makes no sense to me.
Here's my code so you can understand what I'm trying to do:
 using UnityEngine;
 using System.Collections;
 
 public class CubeScript : MonoBehaviour {
 
     public GameObject cube;
 
     Touch userTouch = Input.GetTouch(0);
 
     // Use this for initialization
     void Start () {
         cube = GameObject.Find("Cube");
     }
     
     // Update is called once per frame
     void Update () {
         if (userTouch.position == cube.transform.position;) //this is underlined red
     
     }
 }
 
               Thanks in advance.
Answer by Jason2014 · Apr 24, 2016 at 10:15 AM
For conversion in C# you can write something like this:
Vector2 some2DVector = (Vector2) transform.position;
Just type Vector2 in parenthesis in condition just after operator.
 if (userTouch.position == (Vector2) cube.transform.position)
 {
    // do something (insert semicolon here, at the end of instruction)
 }
 
               However, you made a mistake. You mustn't write semicolon in condition because this is not a instruction.
Your answer
 
             Follow this Question
Related Questions
Operator '==' is ambiguous on operands of type 'Vector2' and 'Vector3' 1 Answer
How To Duplicate Canvas To Follow Player 0 Answers
how to save positions in Vector3 Array und move playerobjekt to the saved position in array's?? 1 Answer
Having trouble with Vectors 1 Answer
New Vector2 won't take effect when called from another script in the same GameObject. 0 Answers