Skip to content

Instantly share code, notes, and snippets.

@johro
Created July 17, 2015 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johro/37f49a20d032e88f3a8d to your computer and use it in GitHub Desktop.
Save johro/37f49a20d032e88f3a8d to your computer and use it in GitHub Desktop.
Photon Unity Networking (Animation)
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