得到两点之间的距离并判断是否在范围内 [随笔]

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour {
    //测试点1
    Vector3 v1 = new Vector3(0,0,0);
    //测试点2
    Vector3 v2 = new Vector3(1,1,1);
    //核定距离
    float attackRange = 1.2f;

void Update () {
if(Input.GetMouseButtonDown(0)){


            Debug.Log(ChooseMethod());
        }
}
    /// <summary>
    /// 得到两点之间的距离,并判断是否在范围之内,得到返回值
    /// </summary>
    /// <returns></returns>
    private bool  ChooseMethod()
    {
        bool attackRangeCheck = Vector3.Distance(v1 , v2) <= attackRange;
        return attackRangeCheck;
    }
}
posted @ 2018-06-09 14:16  低小调  阅读(75)  评论(0编辑  收藏  举报