-
2020-05-12 [unity / 같이 이동]C#/수업내용 2020. 5. 12. 18:49
앞서 썼던 글 //
캐릭터 오브젝트와 구체 같이 이동이 됨 앞서 적은거와 같음.
오늘 생각한거는 해당 구체를 회전 시킨다는 생각을 하고있었음.
LookAt 과 Translate 를 같이 쓰니 회전해서 잘되는 줄 알았음.
LookAt 명확한 파악 필요.
피드백 결과 GameObject를 두고 하위에 둬서 해당 GO 자체를 돌리면 해당 구체가 돌아감.
이동할때는 캐릭터포지션 = 구체오브젝트포지션 을 하면 같이 이동하는 듯이 됨.
구조? 좀 더 생각해야 할듯 싶음.
Test >
더보기123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354using System.Collections;using System.Collections.Generic;using UnityEngine;public class Test : MonoBehaviour{public TestHero testHero;public Shield shield;public GameObject sphere;public float speed;private Animation anim;private Vector3 target;private bool isMove;// Start is called before the first frame updatevoid Start(){this.target = new Vector3(0, 0, 5);this.anim = testHero.model.GetComponent<Animation>();}public void Move(){isMove = true;this.anim.Play("run@loop");}public void Stop(){this.anim.Play("idle@loop");}// Update is called once per framevoid Update(){//var distance = Vector3.Distance(this.target, this.testHero.model.transform.position);this.testHero.transform.Translate(Vector3.forward * 0.5f * Time.deltaTime);this.shield.transform.position = this.testHero.transform.position;// if(distance <= 0.02f)// {// isMove = false;// this.Stop();// }}}cs Shield >
더보기123456789101112131415161718192021222324252627282930313233using System.Collections;using System.Collections.Generic;using UnityEngine;public class Shield : MonoBehaviour{public GameObject model;public TestHero target;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){this.transform.Rotate(Vector3.up * 100 * Time.deltaTime);//this.target = FindObjectOfType<TestHero>();// var look = (this.target.transform.position - this.transform.position).normalized;//this.transform.LookAt(this.target.transform);// this.transform.Rotate(this.target.transform.position * 1 * Time.deltaTime);//this.transform.Translate(Vector3.right * 2 * Time.deltaTime);//}}cs TestHero>
1234567891011121314151617181920using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.iOS;public class TestHero : MonoBehaviour{public GameObject model;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}}cs 'C# > 수업내용' 카테고리의 다른 글
2020-05-14 [unity / 어제에 이어서] (0) 2020.05.14 2020-05-13 [unity / ui 무기선택 및 공격모션 ] (0) 2020.05.13 2020-05-11 [unity] (0) 2020.05.11 2020-05-08 [대략적 lifecycle] (0) 2020.05.08 2020-05-08 [unity / Clone] (0) 2020.05.08