Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace PUNTutorial
- {
- public class Missile : MonoBehaviour
- {
- [SerializeField] ParticleSystem trail;
- [SerializeField] ParticleSystem explosion;
- [SerializeField] Rigidbody rbody;
- public int damage = 10;
- PlayerShoot missileOwner;
- float speed = 60f;
- void FixedUpdate()
- {
- rbody.MovePosition(transform.position + transform.forward * speed * Time.fixedDeltaTime);
- }
- public void SetOwner(PhotonView ownerView)
- {
- missileOwner = ownerView.GetComponent<PlayerShoot>();
- }
- void OnTriggerEnter(Collider other)
- {
- if(other.CompareTag("Player"))
- {
- var hitPlayer = other.GetComponent<PlayerHealth>();
- if (hitPlayer.photonView.isMine)
- {
- if (missileOwner.photonView.viewID == hitPlayer.photonView.viewID) return;
- hitPlayer.DoDamage(this);
- missileOwner.photonView.RPC("RPC_AddScore", missileOwner.photonView.owner, 25);
- }
- }
- DestroyMissile();
- }
- void DestroyMissile()
- {
- trail.transform.SetParent(null);
- trail.Stop(true, ParticleSystemStopBehavior.StopEmitting);
- explosion.transform.SetParent(null);
- explosion.Play();
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement