ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-05-12 [unity / 같이 이동]
    C#/수업내용 2020. 5. 12. 18:49

    앞서 썼던 글 // 

     

    캐릭터 오브젝트와 구체 같이 이동이 됨 앞서 적은거와 같음.

    오늘 생각한거는 해당 구체를 회전 시킨다는 생각을 하고있었음.

    LookAt 과 Translate 를 같이 쓰니 회전해서 잘되는 줄 알았음. 

    LookAt 명확한 파악 필요. 

     

    피드백 결과 GameObject를 두고 하위에 둬서 해당 GO 자체를 돌리면 해당 구체가 돌아감.

     

    이동할때는 캐릭터포지션 = 구체오브젝트포지션 을 하면 같이 이동하는 듯이 됨. 

    구조? 좀 더 생각해야 할듯 싶음. 

     

     

    Test > 

    더보기
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    using 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 update
        void Start()
        {
          
            this.target = new Vector3(005);
            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 frame
        void 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 >

     

    더보기
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    using 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 update
        void Start()
        {
            
        }
     
        // Update is called once per frame
        void 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> 

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    using 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 update
        void Start()
        {
         
        }
        // Update is called once per frame
        void 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
Designed by Tistory.