diff = Target.position - transform.position;

diff.x = 0;

diff.y = 0;

Vector3 pos1 = Vector3.zero;

pos1[0] = 30;

pos1[1] = 20;

pos1[2] = 10;

pos1.x = 30;

Target.position = pos1;

//Target.position.Set(30, 0, 0);

Target.position = new Vector3(30, 0, 0);

//Target.position.x = 30;  error     요렇게는 못써요..


using UnityEngine;

using System.Collections;


public class ExFollow : MonoBehaviour {

public Transform[] Target = new Transform[2];

Vector3 diff;

int count = 0;

int index = 0;

// Use this for initialization

void Start () {

GetDiff();

}

void GetDiff(){

diff = Target[index].position - transform.position;

}

// Update is called once per frame

void Update () {

if(Input.GetKeyDown(KeyCode.Space) && index < Target.Length){

transform.position += diff * 0.1f;

count++;

if(count > 10){

count = 0;

index++;

GetDiff();

}

}

}

}




using UnityEngine;

using System.Collections;


public class ExMove : MonoBehaviour {

Vector3[] pos = new Vector3[4]{new Vector3(15, 0, 15), new Vector3(-15, 0, 15), new Vector3(-15, 0, -15), new Vector3(15, 0, -15)};

int index = 0;

int count = 0;

int mode = 0;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

if(Input.GetKeyDown(KeyCode.Space)){

transform.position = pos[index];

index++;

print (index);

if(index >= pos.Length)  //인덱스 초기화

index = 0;

}

if(Input.GetKey(KeyCode.UpArrow))

transform.localScale = transform.localScale + Vector3.one * 0.01f;

if(Input.GetKey(KeyCode.DownArrow))

transform.localScale = transform.localScale - Vector3.one * 0.01f;

}

}


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

Target.position.x 에 대한 고찰  (0) 2014.04.29
차이를 이용하여 이동시켜 보잨ㅋㅋ  (0) 2014.04.29
벡터 크기증가와 이동  (0) 2014.04.29
좌우로 움직이는 로봇  (0) 2014.04.29
추축축  (0) 2014.04.28

using UnityEngine;

using System.Collections;


public class ExMove : MonoBehaviour {

Vector3[] pos = new Vector3[5]{new Vector3(5, 0, 0), new Vector3(0, 0, 5), new Vector3(-5, 0, 0), new Vector3(0, 0, 5), new Vector3(0, 5, 0)};  벡터 초기화

// Use this for initialization

void Start () {

// transform.localScale += new Vector3(2, 3, 2) * 2.0f;

}

// Update is called once per frame

void Update () {

//transform.localScale = transform.localScale * 1.001f; 크기를 늘리는 것.

//transform.localScale += new Vector3(0.1f, 0.1f, 0.1f);크기를 늘리는 것.

//transform.localScale = transform.localScale + Vector3.one * 0.01f;크기를 늘리는 것.

if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) 위쪽 키를 누르면 크기가 증가

transform.localScale = transform.localScale + Vector3.one * 0.01f;

if(Input.GetKey(KeyCode.DownArrow))                                        아래쪽 키를 누르면 크기가 증가

transform.localScale = transform.localScale - Vector3.one * 0.01f;

/*

if(Input.GetKey(KeyCode.LeftArrow))

transform.position += Vector3.left * Time.deltaTime;

if(Input.GetKey(KeyCode.RightArrow))

transform.position += Vector3.right * Time.deltaTime;

*/

}

}


using UnityEngine;

using System.Collections;


public class ExVector : MonoBehaviour {

public int mode = 0;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

//transform.position += Vector3.right * 5 * Time.deltaTime;

//transform.position += Vector3.up * 5 * Time.deltaTime;

print (transform.position);

if(mode == 0){

transform.position += Vector3.right * 5 * Time.deltaTime;

if(transform.position.x > 10){

mode = 1;

}

}

if(mode == 1){

transform.position += Vector3.left * 5 * Time.deltaTime;

if(transform.position.x < -10){

mode = 0;

}

}

}

}




오른손 x축

머리 y축

가슴 z축







using System.Collections;


public class Ex6_9 : MonoBehaviour {

void MyMethod_0(int a = 0){

print(a);

}

void MyMethod_1(int a = 0, int b = 0){

        print (a + " " + b);

}

void MyMethod_2(int a, int b, int c = 10, int d = 20){

print (a + ", " + b + ", " + c + ", " + d);

}

void PrintProfile(string name = "KIM", string phone = "010"){

print (name + "," + phone);

}

// Use this for initialization

void Start () {

MyMethod_0();

MyMethod_1(20);

MyMethod_2(20, 30);

PrintProfile();

PrintProfile("Park");

PrintProfile(phone:"020-494-4844");

PrintProfile("Park", "010-33939-3333");

}

// Update is called once per frame

void Update () {

}

}



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

좌우로 움직이는 로봇  (0) 2014.04.29
추축축  (0) 2014.04.28
: 을 이용 출력 순서가 바뀌어도 상관이 없다.  (0) 2014.04.22
params  (0) 2014.04.22
params 가변인자  (0) 2014.04.22

using UnityEngine;

using System.Collections;


public class Ex6_8 : MonoBehaviour {

void PrintProfile(string name, string phone){

print ("Name=" + name + "Phone" + phone);

}

// Use this for initialization

void Start () {

PrintProfile(name:"Park", phone:"012-111-0000");

   PrintProfile(phone:"012-1431-0000", name:"Steven");


}

// Update is called once per frame

void Update () {

}

}



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

추축축  (0) 2014.04.28
선택적 매개변수 (기본값이 있을때 매개변수를 생략)  (0) 2014.04.22
params  (0) 2014.04.22
params 가변인자  (0) 2014.04.22
params 매개변수 제한이 없다.  (0) 2014.04.22

.4453125using UnityEngine;

using System.Collections;


public class Ex1 : MonoBehaviour {


// Use this for initialization

void Start () {

int t = GetTotal("10", "20", "30", "40", "50", "60", "70");

print (t);

int t2 = GetTotal2("10", "20", "30", "40", "50", "60", "70");

print (t2);

}

int GetTotal (params string[] args){

int total = 0;

for(int i = 0; i < args.Length; i++){

int num = int.Parse(args[i]);

total += num;

}

return total;

}

int GetTotal2 (params string[] args){

int total = 0;

int num = 0;

for(int i = 0; i < args.Length; i++){

if(int.TryParse(args[i], out num)){

total += num;

}

}

return total;

}

// Update is called once per frame

void Update () {

}

}


.4453125using System.Collections;


public class chap6_7 : MonoBehaviour {


// Use this for initialization

void Start () {

Log("2014:04:22","items23", "zone243");

Log2("test", "2014:04:22","items23", "zone243");

print (Sum (1, 2,3,4,54,5,5,6,6));

GetTypeNames (1, "test", 3.14);

}

string Sum(params int[] args){

int sum = 0;

string text = " ";

for(int i = 0; i < args.Length ; i++){

sum += args[i];

text += sum.ToString();

}

return text;

}

void Log(params string[] args){

string text = " ";

for(int i =0; i < args.Length; i++){

text += args[i] + ", ";

}

print ("[test1] -" + text);

}

void Log2(params string[] args){

string s = "";

string format = "";

for(int i = 0; i < args.Length; i++){

format += "[{" + i.ToString() + "}]";

}

s = string.Format (format, args);

//s = string.Format ("stirng: [{0}][{1}][{2}][{3}]", args[0], args[1], args[2], args[3]);

print (s);

}

void GetTypeNames(params object[] args){

for(int i = 0; i < args.Length ; i++){

print (args[i].GetType().ToString());

}

}

// Update is called once per frame

void Update () {

}

}



+ Recent posts