using UnityEngine;

using System.Collections;


public class Example1 : MonoBehaviour {

/*

string GetInfo(string lastName, string firstName, int age){

return firstName + "," + lastName + ",Age"=+age;

}

*/

int Add(int a, int b){

return a+b;

}

public GameObject Cube;

public GameObject Silinder;

public int dir = 0;

/*

int Calc(int a, int b, out int result){

result = a + b;

result3 = "ok";

return a - b;

}

*/

public int Count = 10;

int Sum(int Count){

int sum1 = 0;

int sum = 0;

for(int i = 1; i<=Count; i++){

sum = Add (sum1, i);

sum1++;

}

return sum;

}

// Use this for initialization

void Start () {

int count = 10;

int result = Sum (Count);

Debug.Log (count+ result);

/*

string fullname = GetFullName("kim", "yuna");

Debug.Log (fullname);

int result = Add (30, 20);

Debug.Log(result);

//int result4;

//Add(30,20, out result2);

//Debug.Log (result);

int result3;

Calc (30, 20, out result3);

Debug.Log("result3_1="+result3 +"result3_2="+result);

*/

}

void moveLeft(GameObject object1){

object1.transform.Translate(new Vector3(-0.1f, 0, 0));

//object1.transform.Rotate(new Vector3(10f, 10f, 10f));

//object1.transform.localScale = new Vector3(10, 10, 10);

}

void moveRight(GameObject object2){

object2.transform.Translate(new Vector3(0.1f, 0, 0));

}

// Update is called once per frame

void Update () {

if (dir <0//director

moveLeft (Cube);

else if(dir >0)

moveRight(Cube);

}

//1per 60

void OnGUI(){

if(GUI.Button(new Rect(10,10,100,100), "Move Left")){

Debug.Log ("Clicked1");

//moveLeft(Cube);

dir = -1;

}

if(GUI.Button(new Rect(120,10,100,100), "stop")){

Debug.Log ("Clicked2");

//moveRight(Silinder);

dir = 0;

}

if(GUI.Button(new Rect(230,10,100,100), "Move Right")){

Debug.Log ("Clicked2");

//moveRight(Silinder);

dir = 1;

}

}

}




'Computer Language > 유니티' 카테고리의 다른 글

자료형(실수)  (0) 2014.03.31
자료형(정수)  (0) 2014.03.31
탱크 이동  (0) 2014.03.28
고스톱 만들기(두 좌표의 차이를 이용하여 이동)  (0) 2014.03.28
큐브 회전  (0) 2014.03.28



using UnityEngine;

using System.Collections;


public class Tank1 : MonoBehaviour {

int state = 1;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

float speed = 0.2f;

float bound = 15.0f;

if (state == 1) {

if (transform.position.z < bound)

transform.Translate(0.0f, 0.0f, speed);

else {

transform.Rotate(0, 90, 0);

state = 2;

}

}

else if (state == 2) {

if (transform.position.x < bound)

transform.Translate(0.0f, 0.0f, speed);

else{

transform.Rotate(0, 90, 0);

state = 3;

}

}

else if (state == 3) {

if (transform.position.z > -bound)

transform.Translate(0.0f, 0.0f, speed);

else{

state = 4;

transform.Rotate(0, 90, 0);

}

}

else if (state == 4) {

if (transform.position.x > -bound)

transform.Translate(0.0f, 0.0f, speed);

else{

transform.Rotate(0, 90, 0);

state = 5;

}

}

else if (state == 5) {

if (transform.position.z < bound)

transform.Translate(0.0f, 0.0f, speed);

else{

state = 6;

}

}

}

}




//hp mp 이용 

/*

while (true) {

hp -= 10;

mp -= 10;

level += 1;

if (mp < 0)

mp = 0;

Debug.Log ("Hp = " + hp + ", Mp = " + mp);

if (mp <= 0 && hp <= 0)

break;

}

Debug.Log ("while end");

*/

/*

short a = 0x0001; // ~00000001

short b = 0x0003; // ~00000010

int c = a & b;

int d = a | b;

Debug.Log ("a = " + a);

Debug.Log ("b = " + b);

Debug.Log ("c = " + c);

Debug.Log ("d = " + d);

*/

/*

int a = 1 << 2;

int b = 8 >> 2;

int c = 1 << (2 + (8 >> 2));

int d = (1 << 2) + (8 >> 2);

Debug.Log ("a = " + a);

Debug.Log ("b = " + b);

Debug.Log ("c = " + c);

Debug.Log ("d = " + d);

*/

/*

if (true && false || true && true) {

Debug.Log ("true");

}

else {

Debug.Log ("false");

}

*/

/*

int score = 250;

if (score >= 300) {

Debug.Log ("1st");

}

else if (score >= 250) {

Debug.Log ("2nd");

}

else if (score >= 200) {

Debug.Log ("3rd");

}

else if (score >= 150) {

Debug.Log ("4th");

}

else if (score >= 100) {

Debug.Log ("5th");

}

else if (score >= 50) {

Debug.Log ("6th");

}

else {

Debug.Log ("etc");

}

*/

/*

string name1 = "kim";

if (name1 == "kim") {

Debug.Log ("true");

}

else {

Debug.Log ("false");

}

*/

/*

for (i = 1; i <= 5; i++) {

Debug.Log ("i = " + i);

}

*/

/*

Debug.Log ("x = " + transform.forward.x);

Debug.Log ("y = " + transform.forward.y);

Debug.Log ("z = " + transform.forward.z);

*/

/*

Debug.Log ("scale.x = " + transform.localScale.x);

float scale = transform.localScale.x - 2;

Debug.Log ("scale.x = " + scale);

*/

 

/*

int x = 20;

int y = 30;

int result = x * y;

Debug.Log ("x = " + x + ", y = " + y + ", result = " + result);

*/


/*

Debug.Log ("Name = " + this.name);

Debug.Log ("x = " + transform.position.x + ", y = " + transform.position.y

+ ", z = " + transform.position.z);

*/

/*

string lastName = "Hong";

string firstName = "Gil Dong";

string Age = "30";

Debug.Log (lastName + ", " + firstName + ", age = " + Age);

*/

/*

int i = 100;

int j = 200;

int sum = 0;

sum = i + j;

Debug.Log ("sum = " + sum + ", j = " + j + ", i = " + i);

*/

/*

char c1 = 'c';

short s1 = 16000;

string name1 = "KOREA 2002";

Debug.Log("Hello, world!");

Debug.Log ("i = " + i);

Debug.Log ("c = " + c1);

Debug.Log ("s = " + s1);

Debug.Log ("name = " + name1);

*/



'Computer Language > 유니티' 카테고리의 다른 글

자료형(정수)  (0) 2014.03.31
왼쪽 오른쪽 이동 그리고 정지  (0) 2014.03.31
고스톱 만들기(두 좌표의 차이를 이용하여 이동)  (0) 2014.03.28
큐브 회전  (0) 2014.03.28
c#  (0) 2014.03.28


using UnityEngine;

using System.Collections;


public class GoStop : MonoBehaviour {

public GameObject Cube1;

public GameObject Cube2;

public GameObject Cube3;

public GameObject Target;

float x1, y1, z1;

float x2, y2, z2;

float x3, y3, z3;

// Use this for initialization

void Start () {

x1 = Target.transform.position.x - Cube1.transform.position.x;

y1 = Target.transform.position.y - Cube1.transform.position.y;

z1 = Target.transform.position.z - Cube1.transform.position.z;

Debug.Log("x1= " + x1 + ",y1= " + y1 + "z1 =" +z1);

x2 = Target.transform.position.x - Cube2.transform.position.x;

y2 = Target.transform.position.y - Cube2.transform.position.y;

z2 = Target.transform.position.z - Cube2.transform.position.z;

Debug.Log("x2= " + x2 + ",y2= " + y2 + "z2 =" +z2);

x3 = Target.transform.position.x - Cube3.transform.position.x;

y3 = Target.transform.position.y - Cube3.transform.position.y;

z3 = Target.transform.position.z - Cube3.transform.position.z;

Debug.Log("x3= " + x3 + ",y3= " + y3 + "z3 =" +z3);


}

// Update is called once per frame

void Update () {

if(Cube1.transform.position.z <Target.transform.position.z)

Cube1.transform.Translate(x1*0.01f,y1*0.01f,z1*0.01f);

if(Cube2.transform.position.z <Target.transform.position.z)

Cube2.transform.Translate(x2*0.01f,y2*0.01f,z2*0.01f);

if(Cube3.transform.position.z <Target.transform.position.z)

Cube3.transform.Translate(x3*0.01f,y2*0.01f,z3*0.01f);

}

}



짧은코드

using UnityEngine;

using System.Collections;


public class GoStop1 : MonoBehaviour {

public GameObject cube_1; //

public GameObject cube_2;

public GameObject cube_3;

public GameObject Target;

Vector3 v1, v2, v3;

// Use this for initialization

void Start () {

cube_1.rigidbody.AddForce(new Vector3(0,100,0)); //물체의 발사는 오브젝트.rigidbody.AddFroce(방향*힘)  공간벡터 Vector3(x,y,z)

cube_1.rigidbody.AddForce(Vector3.up*1000);

v1 = Target.transform.position - cube_1.transform.position;

v2 = Target.transform.position - cube_2.transform.position;

v3 = Target.transform.position - cube_3.transform.position;

Debug.Log("v1= " + v1 + ",v2= " + v2 + "v3 =" +v3);


}

// Update is called once per frame

void Update () {

if(cube_1.transform.position.z <Target.transform.position.z)

cube_1.transform.Translate(v1.x*0.01f,v1.y*0.01f,v1.z*0.01f);

if(cube_2.transform.position.z <Target.transform.position.z)

cube_2.transform.Translate(v2.x*0.01f,v2.y*0.01f,v2.z*0.01f);

if(cube_3.transform.position.z <Target.transform.position.z)

cube_3.transform.Translate(v3.x*0.01f,v3.y*0.01f,v3.z*0.01f);

}

}



'Computer Language > 유니티' 카테고리의 다른 글

자료형(정수)  (0) 2014.03.31
왼쪽 오른쪽 이동 그리고 정지  (0) 2014.03.31
탱크 이동  (0) 2014.03.28
큐브 회전  (0) 2014.03.28
c#  (0) 2014.03.28

+ Recent posts