[RESOLVIDO] Modificação no Script
2 participantes
SchultzGames :: UNITY 3D :: Resolvidos
Página 1 de 1
[RESOLVIDO] Modificação no Script
Como eu poderia adicionar a classe publica usando MonoBehavior nesse script? :
- Código:
using UnityEngine;
using System.Collections;
public class BoltPlayer :Bolt.EntityBehaviour<IPlayerState>{
public GameObject proxyBody;
public bool isControlled { get; set; }
private Transform fpsCamera = null;
private Transform fpsPlayer = null;
private Transform fpsWeapons = null;
private void Awake() {
isControlled = false;
fpsCamera = transform.Find("!!!FPS Camera");
fpsPlayer = transform.Find("!!!FPS Player");
fpsWeapons = transform.Find("!!!FPS Weapons");
if (fpsCamera == null || fpsPlayer == null || fpsWeapons == null) {
enabled = false;
}
}
private void Update() {
if (!isControlled) {
fpsCamera.transform.position = fpsPlayer.transform.position;
fpsCamera.transform.rotation = fpsPlayer.transform.rotation;
fpsWeapons.transform.position = fpsPlayer.transform.position;
fpsWeapons.transform.rotation = fpsPlayer.transform.rotation;
}
}
public override void Attached() {
Debug.Log(gameObject.GetInstanceID() + ": Player syncing transform");
// state.FPSPlayerTransform.SetTransforms(GetComponentInChildren<FPSPlayer>().transform);
GetComponentInChildren<FPSPlayer>().GetComponent<Rigidbody>().isKinematic = !entity.IsOwner;
Invoke("CheckControl", 0.1f);
}
private void CheckControl() {
Debug.Log(gameObject.GetInstanceID() + ": CheckControl, isPlayer=" + isControlled);
var isProxy = !isControlled;
fpsPlayer.GetComponent<Rigidbody>().isKinematic = isProxy;
if (proxyBody != null) {
proxyBody.SetActive(isProxy);
}
if (fpsCamera != null) {
fpsCamera.GetComponent<SmoothMouseLook>().enabled = isControlled;
fpsCamera.GetComponentInChildren<Camera>().enabled = isControlled;
fpsCamera.GetComponentInChildren<AudioListener>().enabled = isControlled;
// fpsCamera.GetComponentInChildren<CameraKick>().enabled = isControlled;
fpsCamera.GetComponentInChildren<LeanColliderDamage>().enabled = isControlled;
fpsCamera.GetComponentInChildren<LevelLoadFade>().enabled = isControlled;
fpsCamera.GetComponentInChildren<PainFade>().enabled = isControlled;
}
if (fpsPlayer != null) {
var fpsPlayerScript = fpsPlayer.GetComponent<FPSPlayer>();
fpsPlayerScript.enabled = isControlled;
// fpsPlayer.GetComponent<HorizontalBob>().enabled = isControlled;
// fpsPlayer.GetComponent<VerticalBob>().enabled = isControlled;
fpsPlayer.GetComponent<Ironsights>().enabled = isControlled;
fpsPlayer.GetComponent<FPSRigidBodyWalker>().enabled = isControlled;
fpsPlayer.GetComponent<Rigidbody>().useGravity = isControlled;
fpsPlayer.GetComponent<Rigidbody>().isKinematic = isProxy;
fpsPlayer.GetComponent<DragRigidbody>().enabled = isControlled;
fpsPlayer.GetComponent<WorldRecenter>().enabled = isControlled;
fpsPlayer.GetComponent<InputControl>().enabled = isControlled;
SetBehaviorEnabled<GUIText>(fpsPlayerScript.crosshairUiObj, isControlled);
SetBehaviorEnabled<GUIText>(fpsPlayerScript.healthUiObj, isControlled);
SetBehaviorEnabled<GUIText>(fpsPlayerScript.thirstUiObj, isControlled);
SetBehaviorEnabled<GUIText>(fpsPlayerScript.hungerUiObj, isControlled);
SetBehaviorEnabled<GUIText>(fpsPlayerScript.helpGuiObj, isControlled);
}
if (fpsWeapons != null) {
var fpsWeaponsScript = fpsWeapons.GetComponent<PlayerWeapons>();
fpsWeaponsScript.SelectedWeapon += OnSelectedWeapon;
fpsWeaponsScript.enabled = isControlled;
fpsWeapons.GetComponent<GunSway>().enabled = isControlled;
fpsWeapons.GetComponent<WeaponEffects>().enabled = isControlled;
// SetBehaviorEnabled<GUIText>(fpsWeaponsScript.ammo, isControlled);
foreach (var weapon in fpsWeaponsScript.weaponOrder) {
var wasActive = weapon.activeInHierarchy;
weapon.SetActive(true);
var weaponBehavior = weapon.GetComponent<WeaponBehavior>();
weaponBehavior.enabled = isControlled;
if (isControlled) {
weaponBehavior.FiredWeapon += OnFiredWeapon;
weaponBehavior.DamagedTarget += OnDamagedTarget;
}
weapon.SetActive(wasActive);
}
}
}
private void SetBehaviorEnabled<T>(GameObject go, bool value) where T : Behaviour {
if (go == null) return;
var behavior = go.GetComponent<T>();
if (behavior != null) behavior.enabled = value;
}
private void OnSelectedWeapon(object sender, PlayerWeapons.SelectedWeaponEventArgs e) {
var equipEvent = EquipEvent.Create(Bolt.GlobalTargets.Everyone);
equipEvent.Player = GetComponent<BoltEntity>();
equipEvent.WeaponNumber = e.weaponNumber;
equipEvent.Send();
}
private void OnFiredWeapon(object sender, WeaponBehavior.FiredWeaponEventArgs e) {
var fireEvent = FireEvent.Create(Bolt.GlobalTargets.Everyone);
fireEvent.Player = GetComponent<BoltEntity>();
fireEvent.WeaponNumber = e.weaponNumber;
fireEvent.Direction = e.direction;
fireEvent.Send();
}
private void OnDamagedTarget(object sender, WeaponBehavior.DamagedTargetEventArgs e) {
var damageEvent = DamageEvent.Create(Bolt.GlobalTargets.Everyone);
var boltEntity = e.target.GetComponentInParent<BoltEntity>();
var boltAwareDamageable = e.target.GetComponentInParent<BoltAwareDamageable>() ?? e.target.GetComponentInChildren<BoltAwareDamageable>();
damageEvent.Player = boltEntity;
damageEvent.ID = (boltAwareDamageable == null) ? -1 : boltAwareDamageable.id;
damageEvent.Damage = e.damage;
damageEvent.AttackDir = e.attackDir;
damageEvent.AttackPos = e.attackPos;
damageEvent.Send();
}
public void EquipWeaponOnProxy(BoltEntity entity, int weaponNumber) {
Debug.Log("Equip weapon " + weaponNumber + " on proxy body " + gameObject.GetInstanceID());
}
public void FireWeaponOnProxy(BoltEntity entity, int weaponNumber, Vector3 direction) {
Debug.Log("Fire weapon " + weaponNumber + " on proxy body " + gameObject.GetInstanceID());
}
}
Re: [RESOLVIDO] Modificação no Script
Não entendi bem a sua dúvida, você gostaria de fazer com que essa classe herde MonoBehaviour?
Esse script me parece implementar uma interface, pela sintaxe é o que parece, se esse for o caso, basta adicionar uma vírgula e referenciar MonoBehaviour. Classes podem herdar de outras classes ao mesmo tempo em que implementam uma ou mais interfaces.
Esse script me parece implementar uma interface, pela sintaxe é o que parece, se esse for o caso, basta adicionar uma vírgula e referenciar MonoBehaviour. Classes podem herdar de outras classes ao mesmo tempo em que implementam uma ou mais interfaces.
Re: [RESOLVIDO] Modificação no Script
Vlw por Responder mas o Script Estava procurando o Objeto Player dentro de uma Pasta Resource a qual eu apaguei por engano, ai tive problemas com o MB(MonoBehavior) mas apenas restaurei a pasta e recompilei os scripts e pronto resolvi meu problema.MayLeone escreveu:Não entendi bem a sua dúvida, você gostaria de fazer com que essa classe herde MonoBehaviour?
Esse script me parece implementar uma interface, pela sintaxe é o que parece, se esse for o caso, basta adicionar uma vírgula e referenciar MonoBehaviour. Classes podem herdar de outras classes ao mesmo tempo em que implementam uma ou mais interfaces.
Tópicos semelhantes
» [RESOLVIDO] Script de imã
» [RESOLVIDO] Script em C#
» [RESOLVIDO] Erro SCRIPT C# com Objeto (Script need's to derive from MonoBehaviour)
» [Resolvido]Script PHP ?
» [RESOLVIDO] Script
» [RESOLVIDO] Script em C#
» [RESOLVIDO] Erro SCRIPT C# com Objeto (Script need's to derive from MonoBehaviour)
» [Resolvido]Script PHP ?
» [RESOLVIDO] Script
SchultzGames :: UNITY 3D :: Resolvidos
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos