2021년 4학년 1학기 기업연계프로젝트2
컴퓨터소프트웨어공학과 <원광투어팀>
팀장 : 송유진
팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using System.Collections;using System.Collections.Generic;using UnityEngine;using Valve.VR;
public class shootingInteraction : MonoBehaviour{ public SteamVR_Input_Sources handType; public SteamVR_Behaviour_Pose controllerPose; // controller info
public SteamVR_Action_Boolean shootingAction;
private GameObject collidingObject; private GameObject objectInHand;
private void Update() { //trackpad ��ư�� ���� ��
if (shootingAction.GetLastStateDown(handType)) { if (collidingObject) { ShootingObject(); } }
//trackpad ��ư�� ���� ��
if (shootingAction.GetLastStateUp(handType)) { if (objectInHand) { RelaseObject(); } } }
public void OnTrackpadEnter(Collider other) { SetCollidingObject(other); }
public void OnTrackpadStay(Collider other) { SetCollidingObject(other); }
public void OnTrackpadExit(Collider other) { if (!collidingObject) return; collidingObject = null; }
//�浹 ���� ��ü�� üũ
private void SetCollidingObject(Collider col) { //�̹� �浹 ���̰ų� rigidbody�� ������ ���� ���� ���� ����ó��
if (collidingObject || !col.GetComponent<Rigidbody>()) return; collidingObject = col.gameObject; }
//����
private void ShootingObject() { objectInHand = collidingObject; collidingObject = null;
var joint = AddFixedJoint(); joint.connectedBody = objectInHand.GetComponent<Rigidbody>(); } //joint �߰�
private FixedJoint AddFixedJoint() { FixedJoint joint = gameObject.AddComponent<FixedJoint>(); joint.breakForce = 20000; joint.breakTorque = 20000; return joint; } //����
private void RelaseObject() { if (GetComponent<FixedJoint>()) { GetComponent<FixedJoint>().connectedBody = null; Destroy(GetComponent<FixedJoint>());
objectInHand.GetComponent<Rigidbody>().velocity = controllerPose.GetVelocity(); objectInHand.GetComponent<Rigidbody>().angularVelocity = controllerPose.GetAngularVelocity(); } objectInHand = null; }}
|