/// <summary> /// 全局创建一个血条 /// </summary> /// <returns></returns> public static GameObject CreateInfoItem(string name, string icon, float hp, GameObject target) { GameObject obj = UIManager.sUIManager.GetUIPrefab("UI/Prefab/NPCItem"); if (obj == null) { return(null); } GameObject item = NPCUIList.sNPCUIList.AddChildItem(obj, target); if (item == null) { return(null); } NPCInfoController info = obj.GetComponent <NPCInfoController>(); if (info == null) { return(null); } info.InitInfo(name, icon, hp); return(item); }
// Use this for initialization void Start() { mAnimation = gameObject.GetComponent <Animation>(); mCharacter = gameObject.GetComponent <CharacterController>(); mStartPosition = transform.position; mHPProgressBar = BloodProgress.CreateBloodProgress(this.gameObject, new Vector3(0, 5, 0)); if (mHPProgressBar != null) { mHPProgressBar.SetValue(mHP / mMaxHP); mHPProgressBar.SetText(Mathf.Max(mHP, 0) + "/" + mMaxHP); } mWanderRadius = 15f; mChaseRadius = 20f; mAttackRadius = 7f; mMaxDistance = 30f; mResetTime = 2f; mMoveSpeed = 300f; mState = MonsterState.WALK; NPCInfoController.CreateInfoItem("大龙怪物", "whiteper", mMaxHP, this.gameObject); }