using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class EllipseMove : NetworkBehaviour
{
public float w;//椭圆长
public float h; //椭圆高
public float moveSpeed;
public Vector3 prePos;
public float temp_angle;
private Vector3 _pos_new;
public Vector3 _center_pos;
public bool _round_its_center;
void Start()
{
if (_round_its_center)
{
_center_pos = transform.localPosition;
}
InvokeRepeating("TransformPosition", 5, 5);
}
void Update()
{
_pos_new.x = _center_pos.x + (w * Mathf.Cos(moveSpeed * Time.time * Mathf.Deg2Rad));
_pos_new.z = _center_pos.z + (h * Mathf.Sin(moveSpeed * Time.time * Mathf.Deg2Rad));
_pos_new.y = transform.localPosition.y;
transform.localPosition = _pos_new;
Vector3 rotateVector = _pos_new - prePos;
Quaternion newRotation = Quaternion.LookRotation(rotateVector);
transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, moveSpeed * Time.time);
prePos = _pos_new;
}
private void TransformPosition()
{
GetComponent<NetworkTransform>().enabled = true;
GetComponent<NetworkTransform>().enabled = false;
}
}