#UnityTips – 關於C# Array

一般用途的Array,不需要動態增/減資料

using UnityEngine; 
using System.Collections; 

public int[] shootAchievementGoal; //#1: 這個Array要在editor中輸入資料
private int[] percentage; //#2:這個Array會根據#1的Array的長度(length)而不同,看#3

void Start () 
{
  percentage = new int[shootAchievementGoal.Length]; //#3:這個寫法是用來定義Array長度的
}

public void Report()
{
   for(int i = 0; i < shootAchievementGoal.Length; i++) //#4:每呼叫一次這個function,就用for函式將所有在percentage[] array內的資料更新
   {
  percentage[i] = Mathf.RoundToInt(100 * bubbleShoot / shootAchievementGoal[i]); //#5
   }
}
									

如果需要動態增/減資料,通常用List比較方便,因為有 Add, Remove功能

 

Unity出現access denied與mono develop auto completion失效的解決方式

最近一直有個錯誤一直很礙眼,專案仍可運作,但一行紅色錯誤一直揮之不去就是很礙眼,主要是這個錯誤“unity unauthorizedaccessexception access to the path is denied…”,這個錯誤連帶(可能)使得Mono Develop的自動顯示程式碼的功能也失效了,搞了幾天,現在大概有個解決的方式了

recently, I was annoying by an error “unity unauthorizedaccessexception access to the path is denied…”. This error also failed auto completion in the Mono Develop. Finally, I seems solve this issue today…

Continue reading