C#/수업내용
2020.05.12. 수업내용 - 캐릭터 중심으로 공 공전시키기(Rotate, vector 더하기)
dev_sr
2020. 5. 12. 17:49
1. 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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public TestHero testHero;
public float speed;
public GameObject ball;
private float time;
private float x;
private float z;
public GameObject empty;
// Start is called before the first frame update
void Start()
{
}
void Update()
{
Vector3 dir = this.empty.transform.position;
this.time = Time.deltaTime;
float speed = 30f;
this.empty.transform.Rotate(Vector3.up * time * speed);
var forward = this.empty.transform.forward;
this.ball.transform.position = forward + dir;
this.testHero.transform.Translate(Time.deltaTime * Vector3.forward * 1f);
this.empty.transform.position = this.testHero.transform.position;
//this.ball.transform.RotateAround(dir, Vector3.up, time*100);
}
}
|
2. TestHero
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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()
{
}
}
|