统一角色移动光子网络

时间:2014-09-05 06:40:58

标签: c# unity3d unityscript photon

所以我有一个播放器健康脚本,它有一个函数被调用来收回脚本所在的播放器的健康点。

因此,PlayerOnes健康脚本将跟踪他的健康状况 PlayerTwo将追踪他的。

当检测到子弹碰撞时,它会从碰撞对象的健康脚本中调用takedamage。因此它需要损坏,它适用于NPC,但不适用于网络玩家。

如果P1射击---> P2两次将造成50点伤害,然后再造成50点伤害,但它并没有输出你的死亡,并且它没有注册到玩家的命中,这意味着它不会因为玩家的生命值而受到伤害是0,因此它只检测碰撞并且什么也不做。但它不会执行剩下的代码并转换玩家的位置等。事情是脚本在两台计算机上运行,​​并且在两者上检测到冲突,因此无论它是否联网,它都应该检测它并执行更新并注册它。

有什么想法吗?

using UnityEngine;
using System.Collections;

public class Health : MonoBehaviour {
    public float hitPoints = 100;
    public Transform explosionPrefab;
    private Transform explosion;
    public  float currentHitPoints;
    SpawnSpot[] spawnSpots; 
    private bool dead = false;
    GameObject deadZone;
    // Use this for initialization
    void Start () {
        currentHitPoints = hitPoints;
        spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
    }

    // Update is called once per frame
    void Update () {
        if (currentHitPoints <= 0) {
            deadZone = GameObject.FindWithTag("DeadZone");
            gameObject.transform.position = deadZone.transform.position;
            dead = true;
            Instantiate(explosionPrefab, gameObject.transform.position, gameObject.transform.rotation);
        }

        if (dead) {
                        if (currentHitPoints <= 0){
                        //if (gameObject.transform.name == "Player"{
                        SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
                        Debug.Log (gameObject.transform.name + "Your DEAD");
                        if (Input.GetButtonDown ("Fire1")) {
                                gameObject.transform.position = mySpawnSpot.transform.position;
                                currentHitPoints = 100;
                        }
                }
        }
    }

    [RPC]
    public void TakeDamage(float amt){
        currentHitPoints -= amt;
        Debug.Log ("taking damage");
        if (currentHitPoints <= 0) {
            Die();
        }
    }

0 个答案:

没有答案