using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class TankMovement : NetworkBehaviour {
public float moveSpeed;
public float turnSpeed;
private Rigidbody rb;
private float movementInputValue;
private float turnInputValue;
// ★
private GameObject tankBody;
public override void OnStartLocalPlayer(){
// ★
tankBody = transform.FindChild("Body").gameObject;
tankBody.GetComponent<MeshRenderer>().material.color = Color.red;
}
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
movementInputValue = Input.GetAxis("Vertical");
turnInputValue = Input.GetAxis("Horizontal");
}
void FixedUpdate(){
if(!isLocalPlayer)
return;
Move();
Turn();
}
void Move(){
Vector3 movement = transform.forward * movementInputValue * moveSpeed * Time.deltaTime;
rb.MovePosition(rb.position + movement);
}
void Turn(){
float turn = turnInputValue * turnSpeed * Time.deltaTime;
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
rb.MoveRotation(rb.rotation * turnRotation);
}
}