我試圖使用我的項目符號集合腳本刪除並重新生成一個球員,當他們的健康降到1以下。但是我的腳本來調用統一的c#函數是不是很正常工作,它說該功能即時試圖調用是Unity多人重生從Unityscript調用C#
資產/級別/資源/ bulletCollision.js(27,16):BCE0019: 'SpawnMyPlayer' 不是 'UnityEngine.Component' 中的一員。
此外,這是一個重生死亡球員的正確方法?
NetworkManager.cs:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
public Camera standbyCamera;
// Use this for initialization
SpawnSpot[] spawnSpots;
void Start() {
Connect();
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGui(){
Debug.Log ("OnGui" + PhotonNetwork.connectionStateDetailed.ToString());
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
// Update is called once per frame
void OnJoinedLobby() {
Debug.Log ("Joined Lobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("Joined Room");
SpawnMyPlayer();
}
void SpawnMyPlayer(){
SpawnSpot mySpawnSpot = spawnSpots [ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayer = PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.enabled = false;
((MonoBehaviour)myPlayer.GetComponent("FPSInputController")).enabled = true;
((MonoBehaviour)myPlayer.GetComponent("PlayerCounters")).enabled = true;
((MonoBehaviour)myPlayer.GetComponent("Tankbody")).enabled = true;
((MonoBehaviour)myPlayer.GetComponent("tankMove")).enabled = true;
((MonoBehaviour)myPlayer.GetComponent("CharacterMotor")).enabled = true;
myPlayer.transform.FindChild("Main Camera").gameObject.SetActive(true);
}
}
子彈collision.js:
#pragma strict
var myClip: AudioClip;
var damage :float = 0;
var bullet_force: float = shoot.shootForce;
function OnCollisionEnter (collision : Collision)
{
Destroy(gameObject);
if(collision.transform.name ==("TankBody")){
var hitCount = gameObject.Find("HitCount").GetComponent(GUIText);
damage = Random.Range(10,30);
PlayerCounters.playerHealth -= damage;
hitCount.text = "Hit: " + damage.ToString();
AudioSource.PlayClipAtPoint(myClip, transform.position);
if(PlayerCounters.playerHealth <0){
Destroy(gameObject.Find("Player"));
PlayerCounters.playerHealth = 0;
PlayerCounters.playerKills += 1;
var cs = GameObject.Find("CSharpGameObj");
var script = cs.GetComponent("NetworkManager");
script.SpawnMyPlayer();
}
}
}
我真的認爲將你的代碼重構爲純粹的C#是值得的。如果你不這樣做,它會給你帶來痛苦。 – 2014-09-02 03:12:35
ahh yea這可能是一個好主意,但所有的教程總是在JavaScript中。 – 2014-09-02 03:42:38
我不是摧毀玩家對象,而是重新定位玩家的位置,並將玩家的狀態重置爲他們默認的重生狀態。因爲保持同一個實例的價格更便宜。在處理更多的可丟棄資產(如敵人和物品)時使用「銷燬」。 – Terrance 2014-09-02 19:24:13