• 主页

  • 投资

  • IT

    🔥
  • 设计

  • 销售

  • 共151篇

    Unity - 游戏引擎

关闭

返回栏目

关闭

返回Unity - 游戏引擎栏目

124 - Player - Arrow.cs - 玩家_射箭

作者:

贺及楼

成为作者

更新日期:2023-09-17 11:00:06

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Common;
  5. public class Arrow : MonoBehaviour {
  6. public RoleType roleType;
  7. public int speed = 5;
  8. public GameObject explosionEffect;
  9. public bool isLocal = false;
  10. private Rigidbody rgd;
  11. // Use this for initialization
  12. void Start () {
  13. rgd = GetComponent<Rigidbody>();
  14. }
  15. // Update is called once per frame
  16. void Update () {
  17. rgd.MovePosition( transform.position+ transform.forward * speed * Time.deltaTime);
  18. }
  19. private void OnTriggerEnter(Collider other)
  20. {
  21. if (other.tag == "Player")
  22. {
  23. GameFacade.Instance.PlayNormalSound(AudioManager.Sound_ShootPerson);
  24. if (isLocal)
  25. {
  26. bool playerIsLocal = other.GetComponent<PlayerInfo>().isLocal;
  27. if (isLocal != playerIsLocal)
  28. {
  29. GameFacade.Instance.SendAttack( Random.Range(10,20) );
  30. }
  31. }
  32. }
  33. else
  34. {
  35. GameFacade.Instance.PlayNormalSound(AudioManager.Sound_Miss);
  36. }
  37. GameObject.Instantiate(explosionEffect, transform.position, transform.rotation);
  38. GameObject.Destroy(this.gameObject);
  39. }
  40. }