Skip to content

Commit dd0cb4e

Browse files
committed
Line destroys if not long enough
1 parent c6ae8bc commit dd0cb4e

4 files changed

Lines changed: 40 additions & 16 deletions

File tree

Assets/Draw.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ public class Draw : MonoBehaviour
88
{
99
public GameObject video;
1010
public GameObject line;
11-
private Vector2 touchStart;
1211
private Touch touch;
13-
private GameObject store;
14-
private List<GameObject> doneLine;
12+
public int order;
13+
public float[] lengths;
1514
void Start() {
1615
//Set screen orientation
1716
Screen.orientation = ScreenOrientation.Landscape;
@@ -22,21 +21,14 @@ void Start() {
2221

2322
void Update()
2423
{
25-
//Debug.Log(Input.touchCount);
26-
if (touch.phase == TouchPhase.Ended)
27-
{
28-
Destroy(store);
29-
}
3024
if (Input.touchCount > 0) {
3125
touch = Input.GetTouch(0);
3226
Vector3 touchpos = Camera.main.ScreenToWorldPoint(touch.position);
3327
touchpos.z = 0;
3428
transform.position = touchpos;
3529

3630
if (touch.phase == TouchPhase.Began) {
37-
Debug.Log(touchpos);
38-
touchStart = touchpos;
39-
store = Instantiate(line, transform.position, transform.rotation);
31+
Instantiate(line, transform.position, transform.rotation);
4032
}
4133
}
4234
}

Assets/Line.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45

@@ -7,17 +8,26 @@ public class Line : MonoBehaviour
78
public float height;
89
private Vector3 StartPos;
910
private LineRenderer l;
11+
private float length;
12+
private bool done;
13+
private GameObject script;
14+
15+
private Touch touch;
1016
void Start()
1117
{
1218
StartPos = transform.position;
1319
l = GetComponent<LineRenderer>();
14-
Debug.Log(StartPos);
20+
script = GameObject.Find("DrawAgent");
21+
Draw comp = script.GetComponent<Draw>();
22+
length = comp.lengths[comp.order];
23+
done = false;
1524
}
1625

1726
void Update()
1827
{
19-
if (Input.touchCount > 0) {
20-
Vector3 current = Input.GetTouch(0).position;
28+
if (!done && Input.touchCount > 0) {
29+
touch = Input.GetTouch(0);
30+
Vector3 current = touch.position;
2131
current = Camera.main.ScreenToWorldPoint(current);
2232
current.z = 0;
2333

@@ -30,6 +40,17 @@ void Update()
3040
//l.startColor = c;
3141
//l.endColor = c;
3242
l.useWorldSpace = true;
43+
44+
float distance = Math.Abs(Vector3.Distance(current, StartPos));
45+
if (distance >= length) {
46+
done = true;
47+
script.GetComponent<Draw>().order++;
48+
}
49+
}
50+
if (touch.phase == TouchPhase.Ended && !done)
51+
{
52+
Debug.Log("I should destroy now");
53+
Destroy(gameObject);
3354
}
3455
}
3556
}

Assets/Scenes/SampleScene.unity

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ MonoBehaviour:
237237
m_EditorClassIdentifier:
238238
video: {fileID: 856213505}
239239
line: {fileID: 1945975318650849093, guid: 9dc3f683d960c3d429039267e8ed9fc3, type: 3}
240+
order: 0
241+
lengths:
242+
- 50
243+
- 50
244+
- 50
245+
- 50
246+
- 50
247+
- 50
248+
- 50
249+
- 50
250+
- 50
240251
--- !u!4 &786270579
241252
Transform:
242253
m_ObjectHideFlags: 0

Assets/Video.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class Video : MonoBehaviour
99
{
1010
private VideoPlayer videoPlayer;
11-
public Camera camera;
11+
new public Camera camera;
1212
public void Play() {
1313
camera.backgroundColor = Color.black;
1414
videoPlayer = GetComponent<VideoPlayer>();

0 commit comments

Comments
 (0)