본문 바로가기
IT/유니티

유니티 게임 프로그래밍 12장 예제 구현

by nutrient 2021. 5. 30.
728x90
728x170

Movement

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {

	// Use this for initialization
	void Start () {
		rigidbody.AddForce(Vector3.up * 10.0f,ForceMode.Impulse);
	}

}

 

PickSelect

using UnityEngine;
using System.Collections;

public class PickSelect : MonoBehaviour {

	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButton(0))
		{
			Ray ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
			RaycastHit hit = new RaycastHit();
			if(Physics.Raycast(ray, out hit,Mathf.Infinity))
			{
				hit.collider.gameObject.GetComponent<HingeJoint>().useMotor = true;
				hit.collider.gameObject.GetComponent<HingeJoint>().anchor = new Vector3(-0.5f,0.0f,0.0f);
				hit.collider.gameObject.GetComponent<HingeJoint>().axis = new Vector3(0.0f,0.0f,1.0f);
				hit.collider.gameObject.rigidbody.constraints = RigidbodyConstraints.None;
			}
			   
		}
	
	}
}

 

Rotate

using UnityEngine;
using System.Collections;

public class Rotate : MonoBehaviour {
	
	public float Speed = 100.0f;
	
	// Update is called once per frame
	void Update () {
		
		rigidbody.AddTorque(Vector3.forward * Speed,ForceMode.Impulse);
		
	}
}
728x90
그리드형

댓글