RaycastHIt |
//가상 선을 만드는 함수. -> 가시적으로 Debug.DrawRay(firePos.transform.position,firePos.transform.forward* 5.0f,Color.green); RaycastHit hit;
//가상선을 만들어 인식 가능하게 함. //어디서 , 어느방향으로 ,구조체 hit 을 5 의길이 로... if(Physics.Raycast(transform.position,transform.forward,out hit,5)) { //catch the confliction. if(hit.collider.gameObject.tag == "Door") { currentdoor = hit.collider.gameObject; currentdoor.SendMessage("DoorCheck");
} } |
GameMenu~!! using UnityEngine; using System.Collections; public class GUIManager : MonoBehaviour {
public AudioClip beep; public GUISkin manuSkin; public Rect menuArea; public Rect PlayBtn; public Rect InstructBtn; public Rect quitBtn;
public Rect menuAreaNormalized;
// Use this for initialization void Start () { menuAreaNormalized = new Rect(menuArea.x * Screen.width - (menuArea.width*0.5f) ,menuArea.y * Screen.height -(menuArea.height*0.5f) ,menuArea.width ,menuArea.height); }
// Update is called once per frame void Update () {
}
void OnGUI() { GUI.skin = manuSkin; GUI.BeginGroup(menuAreaNormalized);
if(GUI.Button(new Rect(PlayBtn),"Iand")) { StartCoroutine(ButtonAction("play")); }
if(GUI.Button(new Rect(InstructBtn),"Instruction")) {
}
if(GUI.Button(new Rect(quitBtn),"Quit")) { StartCoroutine(ButtonAction("quit")); }
GUI.EndGroup();
}
IEnumerator ButtonAction(string buttonName) {
audio.PlayOneShot(beep,1.0f);
yield return new WaitForSeconds(1.0f); if(buttonName=="play") { Application.LoadLevel("Game2"); }else if(buttonName == "quit") { Application.Quit(); }else{ }
} } |
Photon (network) |
using UnityEngine; public class PhotonInit : MonoBehaviour {
|
포 위아래로 콘트롤 하는 소스 (mouse scroll) |
using UnityEngine; using System.Collections; public class CannonCtrl : MonoBehaviour {
private Transform tr; private PhotonView pv;
// Use this for initialization void Awake () { pv = PhotonView.Get (this); tr = GetComponent<Transform>(); }
// Update is called once per frame void Update () { // 포 위아래로 콘트롤 하는소 스 . if(pv.isMine){ float angle = Time.deltaTime * Input.GetAxis("Mouse ScrollWheel") * 300.0f; tr.Rotate(angle, 0 ,0); } } } |
TurretCtrl (Raycast 사용) |
using UnityEngine; using System.Collections; public class TurretCtrl : MonoBehaviour { private PhotonView pv; private Transform tr;
private Quaternion currRot; // Use this for initialization void Start () { tr = GetComponent<Transform>(); pv = PhotonView.Get (this); pv.observed = this;
Debug.Log(pv.viewID); Debug.Log(pv.owner); Debug.Log(pv.isMine); }
// Update is called once per frame void Update () { if(pv.isMine){ Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit;
if(Physics.Raycast ( ray, out hit, Mathf.Infinity)){ Vector3 localPos = tr.InverseTransformPoint(hit.point); float angle = Mathf.Atan2 ( localPos.x, localPos.z) * Mathf.Rad2Deg; tr.Rotate(0, angle* Time.deltaTime * 2.0f, 0); } // Debug.DrawRay(ray.origin, ray.direction * 100.0f, Color.green); }else{ tr.rotation = Quaternion.Lerp(tr.rotation, currRot, Time.deltaTime); }
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){ if(stream.isWriting){ stream.SendNext(tr.rotation); }else{ currRot = (Quaternion) stream.ReceiveNext(); } } } |
|
'유니티3D > 함수' 카테고리의 다른 글
케릭터 마우스 포인터지점으로 이동 (0) | 2013.12.04 |
---|---|
UNITY3D 자주쓰는 스크립트_3 (0) | 2013.09.29 |
UNITY3D 자주쓰는 스크립트_2 (0) | 2013.09.27 |
UNITY3D 자주쓰는 스크립트_1 (0) | 2013.09.27 |
Rigidbody.AddForce() (0) | 2013.08.07 |