i found some funny problem,that i have a private field in a monoBehavior script,it attached to the player gameobject,then i instiantiate the player gameObject,that makes a copy of that script,but as i try to change that private field value in the copied script,it doesnt change,i actually insert a break point in visual studio,i can see the expression value,but still it can’t be changed,below is the picture
because of the limitation,i can only post two picture,there’s another one showing that “fillTime” variable is still zero, 6/10=0? i really don’t know what happened.
and here is the script
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
public class PlayerTurnBasedController : MonoBehaviour,ITurnBaseControl
{
private BattleEffect currentBattleEffect;
public BattleEffect CurrentBattleEffect
{
get
{
return currentBattleEffect;
}
}
private TurnBasedStates currentState;
public TurnBasedStates CurrentState
{
get
{
return currentState;
}
}
private float currentFillProgress;
private bool reFill;
private bool enQueue;
[NonSerialized]
private float fillTime;
private float fillRate;
Animator PlayerAnimator;
PlayerDataContainer PlayerDataContainer;
void Start ()
{
PlayerAnimator = GetComponent<Animator>();
PlayerDataContainer = GetComponent<PlayerDataContainer>();
}
void Update ()
{
//Debug.Log("player current state " + CurrentState);
switch (currentState)
{
case TurnBasedStates.Waiting:
break;
case TurnBasedStates.FillingActionBar:
currentState = TurnBasedStates.Waiting;
StartCoroutine("StartFillACTBar");
break;
case TurnBasedStates.StartAction:
Debug.Log("Player turn");
currentState = TurnBasedStates.Waiting;
break;
case TurnBasedStates.UpdateGUI:
break;
case TurnBasedStates.Dead:
break;
default:
break;
}
}
IEnumerator StartFillACTBar()
{
currentFillProgress = 0;
reFill = true;
enQueue = false;
CanvasGroup CanvasGroup = GlobalControl.Instance.PlayerUIList[0].CanvasGroup;
Image fillImage = GlobalControl.Instance.PlayerUIList[0].ActionBar;
while (CanvasGroup.alpha < 1)
{
CanvasGroup.alpha += (1.0f / 0.5f) * Time.deltaTime;
yield return null;
}
CanvasGroup.alpha = 1;
Debug.Log("Player speed " + PlayerDataContainer.PlayerData.Speed);
**fillTime = PlayerDataContainer.PlayerData.Speed / TurnBasedManager.Instance.BattleFillSpeed;**
fillRate = 1 / fillTime;
Debug.Log("fill time " + fillTime);
Debug.Log("BattleFillSpeed " + TurnBasedManager.Instance.BattleFillSpeed);
while (true)
{
while (currentFillProgress < 1 && reFill)
{
currentFillProgress += fillRate * Time.deltaTime;
fillImage.fillAmount = currentFillProgress;
yield return null;
}
if (!enQueue)
{
currentFillProgress = 1;
reFill = false;
enQueue = true;
TurnBasedManager.Instance.ActionQueue.Enqueue(this);
}
yield return null;
}
}
void UpdateGUI()
{
}
public void ChangeBattleState(TurnBasedStates state)
{
currentState = state;
}
IEnumerator StartAction()
{
yield return null;
}
}