Created
July 17, 2015 09:54
-
-
Save johro/37f49a20d032e88f3a8d to your computer and use it in GitHub Desktop.
Photon Unity Networking (Animation)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class UnityChanController : Photon.MonoBehaviour | |
{ | |
[Range(0.0f,10.0f)] | |
public float speed = 0.1f; | |
private Animator anim; | |
private float yRotate = 0.0f; | |
private Rigidbody rigid; | |
// Use this for initialization | |
void Start () { | |
this.anim = this.GetComponent<Animator>(); | |
this.rigid = this.GetComponent<Rigidbody>(); | |
} | |
// Update is called once per frame | |
void Update () { | |
if (photonView.isMine) | |
{ | |
Vector3 move = Move(); | |
float yRotate = Rotate(); | |
//Vector3 move = this.rigid.velocity; | |
this.GetComponent<PhotonTransformView>().SetSynchronizedValues(speed: move, turnSpeed: yRotate); | |
} | |
} | |
/// <summary> | |
/// 移動処理と移動アニメーション | |
/// </summary> | |
private Vector3 Move() | |
{ | |
float v = Input.GetAxis("Vertical"); | |
Vector3 move = this.transform.position +(this.transform.forward.normalized * Time.deltaTime * speed * v); | |
this.transform.position = move; | |
this.anim.SetFloat("RunSpeed", v); | |
return move; | |
} | |
/// <summary> | |
/// 回転制御 | |
/// </summary> | |
private float Rotate() | |
{ | |
float h = Input.GetAxis("Horizontal"); | |
yRotate += h*3; | |
if (Mathf.Abs(h) > 0.1) | |
{ | |
this.transform.eulerAngles = new Vector3(0, yRotate, 0); | |
} | |
return yRotate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment