我正在尝试使用我的子弹收集脚本在玩家的生命值低于 1 时删除并重新生成玩家。但是我调用 unity c# 函数的脚本不太正常,它说我试图调用的函数是
资产/关卡/资源/bulletCollision.js(27,16):BCE0019:“SpawnMyPlayer”不是“UnityEngine.Component”的成员。
这也是重生被杀玩家的正确方法吗?
网络管理器.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);
}
}
子弹碰撞.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();
}
}
}