using UnityEngine;
using System.Collections;
public class Roket : MonoBehaviour {
public Transform target;
public Vector3 targetVector;
public float damage = 15;
public float lifeTime = 30;
public float force = 5;
public Transform explosion;
public Transform parent;
bool forceAdd=false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (parent)
{
if (!forceAdd)
{
rigidbody.AddForce(parent.forward * (parent.rigidbody.velocity.magnitude + 10));
forceAdd = true;
}
}
if (target)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), Time.deltaTime * 15);
constantForce.force = (transform.forward) * force;
//transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * force);
}
else
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(targetVector), Time.deltaTime * 5);
constantForce.force = (transform.forward) * force;
}
lifeTime -= Time.deltaTime;
if (lifeTime <= 0)
{
if (Network.isServer)
{
Boom();
}
}
}
void OnTriggerEnter(Collider other)
{
if (Network.isServer)
{
if (other.tag == "Player")
{
if (other.transform.networkView.isMine)
{
other.transform.networkView.RPC("ApplyDamage", RPCMode.AllBuffered, damage);
}
}
if (other.tag == "Tower")
{
if (other.transform.networkView.isMine)
{
other.transform.networkView.RPC("ApplyDamage", RPCMode.AllBuffered, damage);
}
}
//Destroy(this.gameObject);
Boom();
}
}
void Boom()
{
Network.Instantiate(explosion, transform.position, transform.rotation, networkView.group);
Network.RemoveRPCs(networkView.viewID);
Network.Destroy(this.gameObject);
}
}