unity get angle between two vectors code example

Example 1: get angle between two vectors unity

Vector3 targetDir = target.position - transform.position;
float angle = Vector3.Angle(targetDir, transform.forward);

Example 2: unity multiply xyz of two vectors

// Calculate the two vectors generating a result.
// This will compute Vector3(2, 6, 12)using UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour
{
    void Example()
    {
        print(Vector3.Scale(new Vector3(1, 2, 3), new Vector3(2, 3, 4)));
    }
}

Example 3: check the angle between two game objects unity

Vector3 dir = GameObject1.position - GameObject2.position;
 float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

Tags:

Cpp Example