/// <summary> /// 当角色手里有工具时,进行砍树或采矿 /// </summary> private void HackOrMine() { // 创建射线碰撞目标 RaycastHit hitObject; // 更新射线 faceRay = new Ray(transform.position + transform.up * 0.1f, transform.forward); Debug.DrawRay(transform.position + transform.up * 0.1f, transform.forward); // 射线碰撞检测 bool isHitResourc = Physics.Raycast(faceRay, out hitObject, MaxDis, LayerMask.GetMask("Resource")); if (isHitResourc) { Resource Resblock = hitObject.collider.gameObject.GetComponent <Resource>(); // 获取人物所持工具 GameObject tool = tm.itemInHand; if (Match(Resblock, tool)) { // 若人物手中道具与资源块匹配则进行操作 Resblock.Action(); hack = true; } else { hack = false; } } else { hack = false; } }