using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class ArrayAndList : MonoBehaviour
{
public string [ ] dateArray;//用Array陣列做個固定張數的情場教戰手冊
public List<string> dateList;//用List清單做個活頁式的情場教戰手冊
public List<contact> phoneBook;//用List清單做個電話簿
void Start ( )
{
#region Array陣列
Debug.Log ( "--------以下是Array陣列---------" );
//為了方便理解 以下都使用張數來比喻而不是頁數 因為一張有兩頁...比較複雜
dateArray = new string [ 4 ];// 固定4張紙的筆記本
dateArray [ 0 ] = "0封面Array";//寫入第X張紙的資料 從封面開始
dateArray [ 1 ] = "1、別問:妳這麼漂亮怎麼還單身啊?";
dateArray [ 2 ] = "2、別說:我媽說……";
dateArray [ 3 ] = "3、別提:彼此的舊情人";
Array.Resize ( ref dateArray , 5 );
//Array陣列像是黏死的固定張數筆記本,要新增紙張的話必須重新指定大小
foreach ( var page in dateArray )//秀出筆記本的內容
{
Debug.Log ( page );
}
#endregion
#region List清單
//List清單像是活頁式的筆記本,系統會自動幫你加紙張
Debug.Log ( "--------以下是List清單---------" );
dateList.Add ( "3、別提:彼此的舊情人" );
dateList.Add ( "1、別問:妳這麼漂亮怎麼還單身啊?" );
dateList.Add ( "0封面Array" );
dateList.Add ( "2、別說:我媽說……" );
//dateList.RemoveAt (2);
foreach ( var page in dateList )
{
Debug.Log ( page );
}
Debug.Log ( "--------搜尋含有 [說] 的資料並顯示出來---------" );
foreach ( var page in dateList )
{
if ( page.Contains ( "說" ) )
{
Debug.Log ( page );
}
}
Debug.Log ( "------測試List排序------" );
dateList.Sort ( );
dateList.Reverse ( );
foreach ( var page in dateList )
{
Debug.Log ( page );
}
#endregion
#region 阿婆電話簿
Debug.Log ( "------阿婆的名冊------" );
phoneBook = new List<contact> ( );
phoneBook.Add ( new contact ( "阿花" , 79979 ) );
phoneBook.Add ( new contact ( "阿珠" , 7878578 ) );
phoneBook.Add ( new contact ( "阿霞" , 5201314 ) );
foreach ( var grandma in phoneBook )
{
Debug.Log ( grandma.name + " " + grandma.phoneNumber );
}
}
#endregion
public struct contact//用結構定義聯絡人
{
public string name;//名字
public int phoneNumber;//電話
public contact ( string _name , int _phoneNumber )
{
name = _name;
phoneNumber = _phoneNumber;
}
}
}
❤❤Fungus新課程即將發布,快寫問卷拿優惠❤❤
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
=======================
演出者:http://audionautix.com/
「Audionautix」創作的「Yeah Yeah」是根據「Creative Commons Attribution」(https://creativecommons.org/licenses/by/4.0/) 授權使用
演出者:http://audionautix.com/
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
Buy.cs 內容
記得新建C#檔案的時候就要取名為 Buy 大小寫有區別
========================
=====================
影片的縮圖來源:Designed by Freepik
2016年12月15日 星期四
Unity C# 程式心得分享 情場教戰手冊 (Array + List + Foreach)
2016年11月8日 星期二
Unity C# 程式心得分享 靜態類別
using UnityEngine;
using System.Collections;
public class Girlfriend : MonoBehaviour
{
public class 人類
{
const string 永遠的女神 = "波多野結衣";//設定好之後就不能再修改(執行之後無法再修改)
public void 說出我的女神 ( ) {
Debug.Log ( 名字 + "表示:我的女神只有一個!" );
Debug.Log ("那就是"+永遠的女神+"啊啊啊啊啊" );
}
public string 名字;
public static bool 吃辣;//static 靜態屬性 牽一髮而動全身
//public bool 吃辣; //動態屬性 因人而異
public void 回答吃不吃辣 ( )
{
if ( 吃辣 == true )
{
Debug.Log ( 名字 + "表示:我吃辣" );
}
else
{
Debug.Log ( 名字 + "表示:我不吃辣" );
}
}
public 人類 ( string 父母取的名字 )//構造器 或稱為 建構函式
{
名字 = 父母取的名字;
}
public void 在一起 ( 人類 對象 ) {
Debug.Log ( "就在這個時候"+名字+"跟"+對象.名字+"天雷勾動地火, 怦怦碰碰動動,他們在一起了!");
王大明的女朋友.自己 = 對象;
Debug.Log ( 名字+"現在跟"+王大明的女朋友.自己.名字+"穩定交往中");
}
}
static class 王大明的女朋友 {
public static 人類 自己;
public static string 男朋友 = "大明";
}
void Start ( )
{
人類 王大明 = new 人類 ( "大明" );//出生 同時取好名字
人類 陳阿香 = new 人類 ( "阿香" );//出生 同時取好名字
人類 張阿珠 = new 人類 ( "阿珠" );//出生 同時取好名字
人類.吃辣 = false;
王大明.回答吃不吃辣 ( );
陳阿香.回答吃不吃辣 ( );
// 王大明的女朋友 女朋友2 = new 王大明的女朋友 ( );
// 女朋友1.名字 = "真真";
// 女朋友2.名字 = "泥泥";
// Debug.Log ( "王大明有兩個女友 叫做"+女朋友1.名字+"跟"+女朋友2.名字);
// Debug.Log ( "王大明迷失在他的美夢裡 永遠醒不來了");
王大明.在一起 ( 陳阿香);
Debug.Log ( "相愛容易 相處難 他們兩個分手了");
王大明.在一起 ( 張阿珠 );
王大明.說出我的女神 ( );
}
}
2016年10月24日 星期一
Unity C# 程式心得分享-- 物件 類別 屬性 方法
using UnityEngine;
using System.Collections;
public class NightMarketLife : MonoBehaviour {
class 人類 {//什麼是人類
public string 稱號;//屬性 (特徵)
public int 胃容量 = 100;//屬性 (特徵)
public void 報上大名 ( ) {//方法 (行為)
Debug.Log ( 稱號+"的大名你沒有聽過嗎 哇哈哈!");
}
public void 吃東西 (店家 某個店家 ) {
int 剩餘胃容量 = 胃容量 - 20;
某個店家.產品數量 -= 1;
Debug.Log (稱號+"吃了一份"+某個店家.產品名 );
Debug.Log ( 稱號 + "的胃容量剩下" + 剩餘胃容量+"%" );
Debug.Log ( 某個店家.產品名+"的數量為"+某個店家.產品數量 );
}
}
class 店家 {
public string 店家名;//屬性
public string 產品名;//屬性
public int 產品數量;//屬性
public void 吆喝 ( ) {//方法
Debug.Log ( 店家名+"的老闆吆喝著:來喔 好吃的 "+產品名+" 裡面坐喔~");
}
}
void Start () {
人類 王大明 = new 人類 ( );//王大明出生了
王大明.稱號 = "三重王識賢";
王大明.報上大名 ( );//調用方法(行為)
店家 臭豆腐店 = new 店家 ( );
臭豆腐店.店家名 = "阿香臭豆腐";
臭豆腐店.產品名 = "臭豆腐";
臭豆腐店.產品數量 = 30;
臭豆腐店.吆喝 ( );
王大明.吃東西 ( 臭豆腐店 );
}
// Update is called once per frame
void Update () {
}
}
2016年10月18日 星期二
Unity C# 程式心得分享 for迴圈 while迴圈 loop
using UnityEngine;
using System.Collections;
public class Love : MonoBehaviour {
// Use this for initialization
void Start () {
//沿著愛心逆時針順序跑
// A C
for (int i=1; i<=4 ; i++ )
{
//B
Debug.Log ("for情書傳給第"+i+"位同學");
//B
}
//=============================
int w = 1;
while (w<=4)
{
Debug.Log ( "while情書傳給第" + w + "位同學" );
w++;
}
//=============================
int d = 1;
do
{
Debug.Log ( "do while情書傳給第" + d + "位同學" );
d++;
}
while (d<=4);
}
// Update is called once per frame
void Update () {
}
}
2016年10月12日 星期三
Unity C# 程式心得分享 邏輯運算 關係運算 且 或
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
=======================
using UnityEngine;
using System.Collections;
public class Shopping : MonoBehaviour
{
void Start ( )
{
string 產品名稱 = "好折凳";
string 產品別稱 = "七大武器之首";
Debug.Log ( "主持人:各位觀眾 走過路過千萬別錯過" );
Debug.Log ( "今天介紹" + 產品名稱 + "也就是傳說中的" + 產品別稱 + "他的特色有..." );
int 女助理胸圍公分 = 92;
Color 產品外觀 = Color.red;//紅色 這邊的Color是Unity內建的Color
Debug.Log ( "色胚的身體起了變化" );
Color 色胚喜歡的顏色 = Color.blue;//藍色
int 色胚的大胸部標準公分 = 90;
//以一擋百
if ( 產品外觀 == 色胚喜歡的顏色 || 女助理胸圍公分 < 色胚的大胸部標準公分 )
{
Debug.Log ( "色胚:喔喔 看起來好棒 我要買~" );
}
else
{
Debug.Log ( "色胚:這東西我沒興趣!" );
}
int 產品價格 = 987;
int 其他同類產品最低價 = 999;
bool 產品多用途 = true;
string 產品品牌 = "食神";
Debug.Log ( "龜毛人的腦中激起了漣漪..." );
//缺一不可
if ( 產品價格 < 其他同類產品最低價 && 產品多用途 && 產品品牌 != "銷魂" )
{
Debug.Log ( "龜毛人:多方考慮後買下" + 產品名稱 + "會很划算!" );
}
else
{
Debug.Log ( "龜毛人:這個" + 產品名稱 + "不夠好,我不要買" );
}
}
void Update ( )
{
}
}
「Audionautix」創作的「Hot Mess」是根據「Creative Commons Attribution」(https://creativecommons.org/licenses/by/4.0/) 授權使用演出者:http://audionautix.com/
「Audionautix」創作的「Yeah Yeah」是根據「Creative Commons Attribution」(https://creativecommons.org/licenses/by/4.0/) 授權使用
演出者:http://audionautix.com/
2016年10月2日 星期日
Unity C# 程式心得分享 ( Debug訊息 變數 if 判斷句 )
本教學系列絕非正統教學,但自我期許是趣味教學,裡面的中文變數只是為了教學使用,正式寫專案時還是建議使用英文變數,倘若各路高手發現內容有誤,煩請不吝指教以矯正視聽,感謝
Buy.cs 內容
記得新建C#檔案的時候就要取名為 Buy 大小寫有區別
========================
using UnityEngine;
using System.Collections;
public class Buy : MonoBehaviour
{
void Start ( ) //開始方法
{
//記得後面加半形的分號
//string 紙條內容 = "去幫我買雞排";//字串
int 雞排數量 = 1;//整數
string 口味 = "梅子";
int 奶茶數量 = 2;//整數
float 奶茶甜度 = 0.3f; //有小數點的浮點數
bool 要切 = false; //布林值 是否~~ 告訴我 是還否!!!
//true代表是 false代表否
bool 覺得教學有趣嗎 = true;
Debug.Log ( "老闆我要" + 口味 + "口味的雞排" + 雞排數量 + "片" );
Debug.Log ( "還有" + 奶茶數量 + "杯奶茶, 甜度" + 奶茶甜度 * 10 + "分糖" );
if ( 要切 )//條件判斷式
{
//true時才執行
Debug.Log ( "啊 對了 老闆 我的雞排要切" );
}
else
{
//false時才執行
Debug.Log ( "啊 我的雞排不切喔~" );
}
if ( 覺得教學有趣嗎 )
{
Debug.Log ( "水喔!給你按個讚~" );
}
}
void Update ( )
{
}
}
=====================
影片的縮圖來源:Designed by Freepik
訂閱:
文章 (Atom)