본문 바로가기

Unity/과제

2020-05-07 과제 오른손에 칼붙이기

집에서 유니티로 오늘 강의내용 복습겸 오른손에 칼을 붙여보았다. 지정한 위치(포지션 || 로테이션)에 실체화

--------------------------------------------------------------------------------------------------------------------------------

App.Class

더보기
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
 
public class App : MonoBehaviour
{
    public GameObject[] arrHeroNames;
    public GameObject[] arrMonsterNames;
    public GameObject[] arrWeaponNames;
 
    public Hero hero;
    public Monster monster;
    public Weapon weapon;
 
    public string heroName;
    public string monsterName;
    public string weaponName;
 
    // Start is called before the first frame update
    void Start()
    {
        var newHero = this.CreateHero(heroName);
        this.hero.Init(newHero);
 
        var newMonster = this.CreateMonster(monsterName);
        this.monster.Init(newMonster);
 
        var newWeapon = this.CreateWeapon(weaponName);
        this.weapon.Init(newWeapon);
 
    }
 
    private GameObject CreateHero(string heroname)
    {
        GameObject foundhero = null;
 
        foreach (var model in this.arrHeroNames)
        {
            if (model.name == heroname)
            {
                foundhero = model;
            }
        }
 
        var newHero = UnityEngine.Object.Instantiate(foundhero);
        return newHero;
    }
 
    private GameObject CreateMonster(string monstername)
    {
        GameObject foundMonster = null;
 
        foreach (var model in this.arrMonsterNames)
        {
            if (model.name == monstername)
            {
                foundMonster = model;
            }
        }
 
        var newMonster = UnityEngine.Object.Instantiate(foundMonster);
        return newMonster;
    }
 
    private GameObject CreateWeapon(string weaponname)
    {
        GameObject foundWeapon = null;
 
        foreach (var model in this.arrWeaponNames)
        {
            if (model.name == weaponname)
            {
                foundWeapon = model;
            }
        }
 
        var newWeapon = UnityEngine.Object.Instantiate(foundWeapon);
        return newWeapon;
    }
}
 
 
 

Hero.Class

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Hero : MonoBehaviour
{
    private GameObject hero;
 
    public void Init(GameObject hero)
    {
        this.hero = hero;
        this.hero.transform.SetParent(this.gameObject.transform);
    }
}
 
 
 

Monster.Class 

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Monster : MonoBehaviour
{
    private GameObject monster;
    public void Init(GameObject monster)
    {
        this.monster = monster;
        this.monster.transform.SetParent(this.gameObject.transform);
 
        Quaternion quaternion = Quaternion.Euler(000);
        this.monster.transform.rotation = quaternion;
        this.monster.transform.position = new Vector3(100);
    }
 
}
 
cs

Weapon.Class

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Weapon : MonoBehaviour
{
    private GameObject weapon;
    public void Init(GameObject weapon)
    {
        this.weapon = weapon;
        this.weapon.transform.SetParent(this.gameObject.transform);
        this.weapon.transform.position = new Vector3(0.15f, 0.1f, -0.03f);
    }
 
}
 
 
 

결과

위치 지정 참고 : https://killu.tistory.com/12

 

'Unity > 과제' 카테고리의 다른 글

2020-05-14 과제 게임만들기(미완성)  (0) 2020.05.15
2020-05-08 과제 [병맛달리기]  (0) 2020.05.09