Ejemplo n.º 1
0
    public void OnSyncedTriggerEnter(TSCollision other)
    {
        SyncedHealth health = other.gameObject.GetComponent <SyncedHealth>();

        if (health != null)
        {
            health.TakeDamage(Damage);
        }
    }
    public override void OnSyncedStart()
    {
        tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5));

        GameObject inputManagerObject = GameObject.FindWithTag("InputManager");

        if (inputManagerObject == null)
        {
            Debug.LogError("场景中缺失 SyncedInputManager 对象!");
            return;
        }

        _syncedInputManager = inputManagerObject.GetComponent <SyncedInputManager>();
        if (_syncedInputManager == null)
        {
            Debug.LogError("场景中缺失 SyncedInputManager 组件!");
        }

        if (owner.id.Equals(localOwner.id))
        {
            _currentShot = playerShot;
        }
        else
        {
            _currentShot = enemyShot;
        }

        _syncedHealth = GetComponent <SyncedHealth>();

        // 如果该对象为本地玩家对象,则将其生命值显示到 UI 控件上
        if (owner.id.Equals(localOwner.id))
        {
            GameObject uiCameraObject = GameObject.Find("UICamera");
            if (uiCameraObject != null)
            {
                UIManager uiManager = uiCameraObject.GetComponent <UIManager>();
                if (uiManager != null)
                {
                    uiManager.PlayerHealth = _syncedHealth;
                }
                else
                {
                    Debug.LogError("Can not get the reference of 'HealthText'!");
                }
            }
            else
            {
                Debug.LogError("GameObject 'UICamera' is missing in the current scene!");
            }
        }

        _audioSource = GetComponent <AudioSource>();

        _death = 0;
    }