Skip to content

Instantly share code, notes, and snippets.

@vjgrayman
Last active July 18, 2019 19:51
Show Gist options
  • Save vjgrayman/924bb2fe15301a2bc18a9ec0f9a6d684 to your computer and use it in GitHub Desktop.
Save vjgrayman/924bb2fe15301a2bc18a9ec0f9a6d684 to your computer and use it in GitHub Desktop.
[CSharpSurviver_3] #CSharp
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Array Types
public string[] names;
// 유니티 종료시 리셋됨
public string[] items = new string[5];
// 유니티 종료시 데이터 리셋됨, 데이터 필드는 유지됨
public int[] ages = new int[] {15, 17, 24, 19, 37};
// 모든 필드, 데이터 값이 스크립트에 저장됨
// Start is called before the first frame update
void Start()
{
Debug.Log(names[0]);
Debug.Log(ages[3]);
Debug.Log(items[1]);
}
// Update is called once per frame
void Update()
{
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public string[] names = new string[] { "AAA", "BBB", "CCC", "DDD", "EEE"};
public int[] ages = new int[] { 17, 15, 19, 21, 25 };
public string[] carNames = new string[] { "Car1", "Car2", "Car3", "Car4", "Car5"};
public int randomValue;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
randomValue = Random.Range(0, names.Length);
Debug.Log(randomValue);
Debug.Log("Name: " + names[randomValue]);
Debug.Log("Ages: " + ages[randomValue]);
Debug.Log("CarModel: " + carNames[randomValue]);
}
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public string[] itemName;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
/*
for (int i=0; i<itemName.Length; i++)
{
Debug.Log(itemName[i]);
}
*/
foreach (var item in itemName)
//var = universal Data type
{
if (item == "itemBB")
{
Debug.Log(item);
}
}
}
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Item
{
public int itemID;
public string name;
public string description;
}
public class Player : MonoBehaviour
{
public Item[] myItems;
void Start()
{
foreach (var item in myItems)
{
Debug.Log(item.name);
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
int randomID = Random.Range(0, myItems.Length);
Debug.Log(myItems[randomID].description);
}
}
}
// vim: syntax=CSharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player: MonoBehaviour
{
public GameObject[] cubes;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
foreach(var cube in cubes)
{
cube.GetComponent<MeshRenderer>().material.color = Color.red;
}
}
if (Input.GetKeyDown(KeyCode.A))
{
for (int i=0; i<cubes.Length; i++)
{
cubes[i].GetComponent<MeshRenderer>().material.color = Color.green;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment