Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Commit 34c27ea

Browse files
Update sample script namespaces
1 parent 1088988 commit 34c27ea

File tree

6 files changed

+174
-156
lines changed

6 files changed

+174
-156
lines changed
Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
11
using UnityEngine;
22
using UnityEngine.UI;
33

4-
[RequireComponent(typeof(Text))]
5-
public class FloatFadeOutText : MonoBehaviour
4+
namespace GameEvents
65
{
7-
[SerializeField]
8-
private Vector3 floatDirection = Vector2.up;
6+
[RequireComponent(typeof(Text))]
7+
public class FloatFadeOutText : MonoBehaviour
8+
{
9+
[SerializeField]
10+
private UnityEngine.Vector3 floatDirection = UnityEngine.Vector2.up;
911

10-
[SerializeField]
11-
private Color fadeOutColor = Color.clear;
12+
[SerializeField]
13+
private Color fadeOutColor = Color.clear;
1214

13-
[SerializeField]
14-
private float floatSpeed = 15f;
15+
[SerializeField]
16+
private float floatSpeed = 15f;
1517

16-
[SerializeField]
17-
private float floatDuration = 3f;
18+
[SerializeField]
19+
private float floatDuration = 3f;
1820

19-
private float floatProgress;
20-
private Text floatText;
21-
private Color originalColor;
21+
private float floatProgress;
22+
private Text floatText;
23+
private Color originalColor;
2224

23-
private void Awake()
24-
{
25-
floatText = GetComponent<Text>();
26-
originalColor = floatText.color;
27-
}
25+
private void Awake()
26+
{
27+
floatText = GetComponent<Text>();
28+
originalColor = floatText.color;
29+
}
2830

29-
private void Update()
30-
{
31-
floatText.rectTransform.position = GetTextPosition();
32-
floatText.color = GetTextColor();
31+
private void Update()
32+
{
33+
floatText.rectTransform.position = GetTextPosition();
34+
floatText.color = GetTextColor();
3335

34-
if (floatProgress > 1f) Destroy(gameObject);
36+
if (floatProgress > 1f) Destroy(gameObject);
3537

36-
floatProgress = GetProgress();
37-
}
38+
floatProgress = GetProgress();
39+
}
3840

39-
private Vector3 GetTextPosition()
40-
{
41-
return floatText.rectTransform.position + floatDirection * (floatSpeed * Time.deltaTime);
42-
}
41+
private UnityEngine.Vector3 GetTextPosition()
42+
{
43+
return floatText.rectTransform.position + floatDirection * (floatSpeed * Time.deltaTime);
44+
}
4345

44-
private Color GetTextColor()
45-
{
46-
return Color.LerpUnclamped(originalColor, fadeOutColor, floatProgress);
47-
}
46+
private Color GetTextColor()
47+
{
48+
return Color.LerpUnclamped(originalColor, fadeOutColor, floatProgress);
49+
}
4850

49-
private float GetProgress()
50-
{
51-
return floatProgress + Time.deltaTime / floatDuration;
51+
private float GetProgress()
52+
{
53+
return floatProgress + Time.deltaTime / floatDuration;
54+
}
5255
}
5356
}
Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
11
using UnityEngine;
22
using UnityEngine.UI;
33

4-
[RequireComponent(typeof(Text))]
5-
public class Score : MonoBehaviour
4+
namespace GameEvents
65
{
7-
[Min(0)]
8-
[SerializeField]
9-
private int scoreIncrease = 100;
10-
11-
[SerializeField]
12-
private float scoreEffectYOffset = 10f;
13-
14-
[SerializeField]
15-
private FloatFadeOutText scoreEffectPrefab = default;
16-
17-
private int currentScore;
18-
private Text text;
19-
20-
private void Awake()
6+
[RequireComponent(typeof(Text))]
7+
public class Score : MonoBehaviour
218
{
22-
text = GetComponent<Text>();
23-
}
9+
[Min(0)]
10+
[SerializeField]
11+
private int scoreIncrease = 100;
2412

25-
public void IncreaseScore()
26-
{
27-
currentScore += scoreIncrease;
28-
text.text = currentScore.ToString();
13+
[SerializeField]
14+
private float scoreEffectYOffset = 10f;
2915

30-
InstantiateEffect($"+{scoreIncrease.ToString()}");
31-
}
16+
[SerializeField]
17+
privateFloatFadeOutTextscoreEffectPrefab=default;
3218

33-
private void InstantiateEffect(string effectText)
34-
{
35-
var scoreTransform = transform;
36-
var scorePosition = scoreTransform.position;
19+
private int currentScore;
20+
private Text text;
21+
22+
private void Awake()
23+
{
24+
text = GetComponent<Text>();
25+
}
3726

38-
scorePosition.y += scoreEffectYOffset;
27+
public void IncreaseScore()
28+
{
29+
currentScore += scoreIncrease;
30+
text.text = currentScore.ToString();
3931

40-
var floatEffect = Instantiate(
41-
scoreEffectPrefab,
42-
scorePosition,
43-
Quaternion.identity,
44-
scoreTransform
45-
);
32+
InstantiateEffect($"+{scoreIncrease.ToString()}");
33+
}
4634

47-
var floatText = floatEffect.GetComponent<Text>();
48-
if (floatText != null)
35+
private void InstantiateEffect(string effectText)
4936
{
50-
floatText.text = effectText;
37+
var scoreTransform = transform;
38+
var scorePosition = scoreTransform.position;
39+
40+
scorePosition.y += scoreEffectYOffset;
41+
42+
var floatEffect = Instantiate(
43+
scoreEffectPrefab,
44+
scorePosition,
45+
Quaternion.identity,
46+
scoreTransform
47+
);
48+
49+
var floatText = floatEffect.GetComponent<Text>();
50+
if (floatText != null)
51+
{
52+
floatText.text = effectText;
53+
}
5154
}
5255
}
5356
}
Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
using GameEvents.Transform;
22
using UnityEngine;
33

4-
[RequireComponent(typeof(Camera))]
5-
public class Shooter : MonoBehaviour
4+
namespace GameEvents
65
{
7-
[SerializeField]
8-
private TransformGameEvent shotGameEvent = default;
6+
[RequireComponent(typeof(Camera))]
7+
public class Shooter : MonoBehaviour
8+
{
9+
[SerializeField]
10+
private TransformGameEvent shotGameEvent = default;
911

10-
[SerializeField]
11-
private string shootButton = "Fire1";
12+
[SerializeField]
13+
private string shootButton = "Fire1";
1214

13-
private new Camera camera;
15+
private new Camera camera;
1416

15-
private void Awake()
16-
{
17-
camera = GetComponent<Camera>();
18-
}
17+
private void Awake()
18+
{
19+
camera = GetComponent<Camera>();
20+
}
1921

20-
private void Update()
21-
{
22-
if (IsShoot()) Shoot();
23-
}
22+
private void Update()
23+
{
24+
if (IsShoot()) Shoot();
25+
}
2426

25-
private bool IsShoot()
26-
{
27-
return Input.GetButtonDown(shootButton);
28-
}
27+
private bool IsShoot()
28+
{
29+
return Input.GetButtonDown(shootButton);
30+
}
2931

30-
private void Shoot()
31-
{
32-
var ray = camera.ScreenPointToRay(Input.mousePosition);
32+
private void Shoot()
33+
{
34+
var ray = camera.ScreenPointToRay(Input.mousePosition);
3335

34-
if (Physics.Raycast(ray, out var hit)) shotGameEvent.RaiseGameEvent(hit.transform);
36+
if (Physics.Raycast(ray, out var hit)) shotGameEvent.RaiseGameEvent(hit.transform);
37+
}
3538
}
3639
}
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using UnityEngine;
22
using UnityEngine.Events;
33

4-
publicclassShotHandler:MonoBehaviour
4+
namespaceGameEvents
55
{
6-
[SerializeField]
7-
private UnityEvent onShot = default;
8-
9-
public void HandleShot(Transform shot)
6+
public class ShotHandler : MonoBehaviour
107
{
11-
Destroy(shot.gameObject);
12-
onShot.Invoke();
8+
[SerializeField]
9+
private UnityEvent onShot = default;
10+
11+
public void HandleShot(UnityEngine.Transform shot)
12+
{
13+
Destroy(shot.gameObject);
14+
onShot.Invoke();
15+
}
1316
}
1417
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /