Advertisement
djgaven588

BulletCode

Apr 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public class NonExplosiveBullet : MonoBehaviour, IBullet {
  2.  
  3. public Vector3 velocity {get; private set;}
  4. public Vector3 currentPosition {get; private set;}
  5. public float fallRate {get; private set;}
  6. public float damage {get; private set;}
  7. public float latency {get; private set;}
  8.  
  9.  
  10. public PhotonView firedBy {get; private set;}
  11. private string shooterName;
  12. private bool alreadyHit = false;
  13.  
  14. [Header("Fx")]
  15. public GameObject bulletCollideFx;
  16.  
  17. private void FixedUpdate ()
  18. {
  19. if (alreadyHit)
  20. return;
  21.  
  22. Vector3 timeBasedVelocity = velocity * Time.fixedDeltaTime;
  23. if(latency > 0)
  24. {
  25. timeBasedVelocity += timeBasedVelocity * latency;
  26. latency = 0;
  27. }
  28.  
  29. timeBasedVelocity = BulletMove.UpdateVelocity(timeBasedVelocity);
  30. currentPosition = BulletMove.MovePosition(currentPosition, timeBasedVelocity);
  31.  
  32. Transform hit = BulletMove.BulletHit(currentPosition, timeBasedVelocity);
  33.  
  34. velocity = timeBasedVelocity / Time.fixedDeltaTime;
  35. if(hit != null)
  36. {
  37. if(hit.gameObject != firedBy.gameObject && hit.tag != "Bullet")
  38. {
  39. if(PhotonNetwork.isMasterClient)
  40. {
  41. //Handle in Multiplayer Server
  42. MultiplayerServer.inst.BulletCheck(this);
  43. }
  44. else
  45. {
  46. //Erm, do a thing. You know, that one thing!
  47. }
  48. Instantiate(bulletCollideFx, transform.position, transform.rotation);
  49. Destroy(this.gameObject);
  50. }
  51. }
  52. }
  53.  
  54. public void Setup(Vector3 initialVelocity, float _dropRate, float _bulletDamage, PhotonView _firedFrom, string _shooterName, float _latency)
  55. {
  56. velocity = initialVelocity;
  57. fallRate = _dropRate;
  58. damage = _bulletDamage;
  59. firedBy = _firedFrom;
  60. shooterName = _shooterName;
  61. currentPosition = transform.position;
  62. latency = _latency;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement