Last active
July 23, 2019 14:12
-
-
Save vjgrayman/bc4d75cfb9539caca629807786db8047 to your computer and use it in GitHub Desktop.
[CSharpSurviver_4] #CSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player: MonoBehaviour | |
{ | |
void Start() | |
{ | |
Debug.Log("Start to Call"); | |
myMethod(); | |
Debug.Log("Complete Calling"); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
private void myMethod() | |
{ | |
Debug.Log("myMethod()"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player: MonoBehaviour | |
{ | |
// Script added to Cube(player Game Object) | |
public int health; | |
public void Damage(int damageAmount) | |
{ | |
health -= damageAmount; | |
if (health < 1) | |
{ | |
health = 0; | |
Destroy(this.gameObject); | |
} | |
} | |
private void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
Damage(5); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player : MonoBehaviour | |
{ | |
public GameObject playerCube; | |
private void Start() | |
{ | |
} | |
private void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
ChangeColor(playerCube, Color.blue); | |
} | |
} | |
private void ChangeColor(GameObject obj, Color colorToAssign) | |
{ | |
obj.GetComponent<MeshRenderer>().material.color = colorToAssign; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player : MonoBehaviour | |
{ | |
/* | |
public int total; | |
private void Start() | |
{ | |
Sum(5, 2); | |
} | |
private void Update() | |
{ | |
} | |
private void Sum(int a, int b) | |
{ | |
total = a + b; | |
} | |
*/ | |
// Using Return Type | |
public int total; | |
public int total2; | |
private void Start() | |
{ | |
total= Sum(5, 2); | |
total2 = Sum(10, 3); | |
} | |
private void Update() | |
{ | |
} | |
private int Sum(int a, int b) | |
{ | |
return a + b; | |
} | |
// return 값을 사용할 경우 함수의 데이터 타입을 정해주어야 함 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player: MonoBehaviour | |
{ | |
// Script added to Cube(player Game Object) | |
private void Start() | |
{ | |
transform.position = GetPosition(0, 0, 0); | |
} | |
private void Update() | |
{ | |
} | |
public Vector3 GetPosition(float x, float y, float z) | |
{ | |
Vector3 pos = new Vector3(x, y, z); | |
return pos; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player : MonoBehaviour | |
{ | |
public GameObject[] players; | |
private void Start() | |
{ | |
players = GetAllPlayers(); | |
} | |
private void Update() | |
{ | |
} | |
GameObject[] GetAllPlayers() | |
{ | |
GameObject[] allPlayers = GameObject.FindGameObjectsWithTag("Player"); | |
foreach(var p in allPlayers) | |
{ | |
p.GetComponent<MeshRenderer>().material.color = new Color(Random.value, Random.value, Random.value); | |
} | |
return allPlayers; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player: MonoBehaviour | |
{ | |
public int health; | |
private void Start() | |
{ | |
health = 100; | |
} | |
private void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
if (CheckDeath() == true) | |
{ | |
Damage(Random.Range(5, 20)); | |
} | |
if (CheckDeath() == false) | |
{ | |
health = 0; | |
Debug.Log("the Player is died!"); | |
} | |
} | |
} | |
private void Damage(int damageAmount) | |
{ | |
health -= damageAmount; | |
} | |
public bool CheckDeath() | |
{ | |
return health > 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: syntax=CSharp | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player : MonoBehaviour | |
{ | |
public Vector3[] fivePositions; | |
public int randomIndex; | |
private void Start() | |
{ | |
randomIndex = GetRandom(); | |
transform.position = GetPosition(randomIndex); | |
} | |
private void Update() | |
{ | |
} | |
int GetRandom() | |
{ | |
return Random.Range(0, fivePositions.Length); | |
} | |
Vector3 GetPosition(int Index) | |
{ | |
return fivePositions[Index]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment