Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NonExplosiveBullet : MonoBehaviour, IBullet {
- public Vector3 velocity {get; private set;}
- public Vector3 currentPosition {get; private set;}
- public float fallRate {get; private set;}
- public float damage {get; private set;}
- public float latency {get; private set;}
- public PhotonView firedBy {get; private set;}
- private string shooterName;
- private bool alreadyHit = false;
- [Header("Fx")]
- public GameObject bulletCollideFx;
- private void FixedUpdate ()
- {
- if (alreadyHit)
- return;
- Vector3 timeBasedVelocity = velocity * Time.fixedDeltaTime;
- if(latency > 0)
- {
- timeBasedVelocity += timeBasedVelocity * latency;
- latency = 0;
- }
- timeBasedVelocity = BulletMove.UpdateVelocity(timeBasedVelocity);
- currentPosition = BulletMove.MovePosition(currentPosition, timeBasedVelocity);
- Transform hit = BulletMove.BulletHit(currentPosition, timeBasedVelocity);
- velocity = timeBasedVelocity / Time.fixedDeltaTime;
- if(hit != null)
- {
- if(hit.gameObject != firedBy.gameObject && hit.tag != "Bullet")
- {
- if(PhotonNetwork.isMasterClient)
- {
- //Handle in Multiplayer Server
- MultiplayerServer.inst.BulletCheck(this);
- }
- else
- {
- //Erm, do a thing. You know, that one thing!
- }
- Instantiate(bulletCollideFx, transform.position, transform.rotation);
- Destroy(this.gameObject);
- }
- }
- }
- public void Setup(Vector3 initialVelocity, float _dropRate, float _bulletDamage, PhotonView _firedFrom, string _shooterName, float _latency)
- {
- velocity = initialVelocity;
- fallRate = _dropRate;
- damage = _bulletDamage;
- firedBy = _firedFrom;
- shooterName = _shooterName;
- currentPosition = transform.position;
- latency = _latency;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement