ThirdPersonController









How do I use Third Person Controller
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PickupCamera.cs Copy
41     void OnEnable()
42     {
43         if( this.photonView != null && !this.photonView.isMine )
44         {
45             this.enabled = false;
46             return;
47         }
48
49         if( !cameraTransform && Camera.main )
50             cameraTransform = Camera.main.transform;
51         if( !cameraTransform )
52         {
53             Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
54             enabled = false;
55         }
56
57         m_CameraTransformCamera = cameraTransform.GetComponent();
58
59
60         _target = transform;
61         if( _target )
62         {
63             controller = _target.GetComponent();
64         }
65
66         if( controller )
67         {
68             CharacterController characterController = (CharacterController)_target.GetComponent();
69             centerOffset = characterController.bounds.center - _target.position;
70             headOffset = centerOffset;
71             headOffset.y = characterController.bounds.max.y - _target.position.y;
72         }
73         else
74             Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
75
76
77         Cut( _target, centerOffset );
78     }
File name: ThirdPersonCamera.cs Copy
40     void OnEnable()
41     {
42         if( !cameraTransform && Camera.main )
43             cameraTransform = Camera.main.transform;
44         if( !cameraTransform )
45         {
46             Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
47             enabled = false;
48         }
49
50         m_CameraTransformCamera = cameraTransform.GetComponent();
51
52         _target = transform;
53         if( _target )
54         {
55             controller = _target.GetComponent();
56         }
57
58         if( controller )
59         {
60             CharacterController characterController = (CharacterController)_target.GetComponent();
61             centerOffset = characterController.bounds.center - _target.position;
62             headOffset = centerOffset;
63             headOffset.y = characterController.bounds.max.y - _target.position.y;
64         }
65         else
66             Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
67
68
69         Cut( _target, centerOffset );
70     }
File name: ThirdPersonNetwork.cs Copy
9     void Awake()
10     {
11         cameraScript = GetComponent();
12         controllerScript = GetComponent();
13
14          if (photonView.isMine)
15         {
16             //MINE: local player, simply enable the local scripts
17             cameraScript.enabled = true;
18             controllerScript.enabled = true;
19         }
20         else
21         {
22             cameraScript.enabled = false;
23
24             controllerScript.enabled = true;
25             controllerScript.isControllable = false;
26         }
27
28         gameObject.name = gameObject.name + photonView.viewID;
29     }
File name: NetworkCharacter.cs Copy
17     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
18     {
19         if (stream.isWriting)
20         {
21             // We own this player: send the others our data
22             stream.SendNext(transform.position);
23             stream.SendNext(transform.rotation);
24
25             myThirdPersonController myC = GetComponent();
26             stream.SendNext((int)myC._characterState);
27         }
28         else
29         {
30             // Network player, receive data
31             this.correctPlayerPos = (Vector3)stream.ReceiveNext();
32             this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
33
34             myThirdPersonController myC = GetComponent();
35             myC._characterState = (CharacterState)stream.ReceiveNext();
36         }
37     }
File name: RandomMatchmaker.cs Copy
24     void OnJoinedRoom()
25     {
26         GameObject monster = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
27         monster.GetComponent().isControllable = true;
28         myPhotonView = monster.GetComponent();
29     }

Download file with original file name:ThirdPersonController

ThirdPersonController 138 lượt xem

Gõ tìm kiếm nhanh...