Advertisement
Munchy2007

Missile_Full

Jan 10th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace PUNTutorial
  6. {
  7.     public class Missile : MonoBehaviour
  8.     {
  9.         [SerializeField] ParticleSystem trail;
  10.         [SerializeField] ParticleSystem explosion;
  11.         [SerializeField] Rigidbody rbody;
  12.         public int damage = 10;
  13.         PlayerShoot missileOwner;
  14.         float speed = 60f;
  15.  
  16.         void FixedUpdate()
  17.         {
  18.             rbody.MovePosition(transform.position + transform.forward * speed * Time.fixedDeltaTime);
  19.         }
  20.  
  21.         public void SetOwner(PhotonView ownerView)
  22.         {
  23.             missileOwner = ownerView.GetComponent<PlayerShoot>();
  24.         }
  25.  
  26.         void OnTriggerEnter(Collider other)
  27.         {
  28.             if(other.CompareTag("Player"))
  29.             {
  30.                 var hitPlayer = other.GetComponent<PlayerHealth>();
  31.  
  32.                 if (hitPlayer.photonView.isMine)
  33.                 {
  34.                     if (missileOwner.photonView.viewID == hitPlayer.photonView.viewID) return;
  35.                     hitPlayer.DoDamage(this);
  36.                     missileOwner.photonView.RPC("RPC_AddScore", missileOwner.photonView.owner, 25);
  37.                 }
  38.             }
  39.  
  40.             DestroyMissile();
  41.         }
  42.  
  43.  
  44.         void DestroyMissile()
  45.         {
  46.             trail.transform.SetParent(null);
  47.             trail.Stop(true, ParticleSystemStopBehavior.StopEmitting);
  48.             explosion.transform.SetParent(null);
  49.             explosion.Play();
  50.             Destroy(gameObject);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement