Skip to content

Commit c6ae8bc

Browse files
committed
Added line
It moves with your finger when you touch the screen
1 parent c94783a commit c6ae8bc

3 files changed

Lines changed: 102 additions & 32 deletions

File tree

Assets/Draw.cs

Lines changed: 10 additions & 5 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 System.Numerics;
45
using UnityEngine;
@@ -8,7 +9,9 @@ public class Draw : MonoBehaviour
89
public GameObject video;
910
public GameObject line;
1011
private Vector2 touchStart;
12+
private Touch touch;
1113
private GameObject store;
14+
private List<GameObject> doneLine;
1215
void Start() {
1316
//Set screen orientation
1417
Screen.orientation = ScreenOrientation.Landscape;
@@ -20,19 +23,21 @@ void Start() {
2023
void Update()
2124
{
2225
//Debug.Log(Input.touchCount);
26+
if (touch.phase == TouchPhase.Ended)
27+
{
28+
Destroy(store);
29+
}
2330
if (Input.touchCount > 0) {
24-
Touch touch = Input.GetTouch(0);
31+
touch = Input.GetTouch(0);
2532
Vector3 touchpos = Camera.main.ScreenToWorldPoint(touch.position);
2633
touchpos.z = 0;
2734
transform.position = touchpos;
35+
2836
if (touch.phase == TouchPhase.Began) {
2937
Debug.Log(touchpos);
3038
touchStart = touchpos;
3139
store = Instantiate(line, transform.position, transform.rotation);
3240
}
33-
if (touch.phase == TouchPhase.Ended) {
34-
Destroy(store);
35-
}
3641
}
3742
}
3843

Assets/Line.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@
44

55
public class Line : MonoBehaviour
66
{
7-
// Start is called before the first frame update
7+
public float height;
8+
private Vector3 StartPos;
9+
private LineRenderer l;
810
void Start()
911
{
10-
12+
StartPos = transform.position;
13+
l = GetComponent<LineRenderer>();
14+
Debug.Log(StartPos);
1115
}
1216

13-
// Update is called once per frame
1417
void Update()
1518
{
16-
19+
if (Input.touchCount > 0) {
20+
Vector3 current = Input.GetTouch(0).position;
21+
current = Camera.main.ScreenToWorldPoint(current);
22+
current.z = 0;
23+
24+
Vector3[] pos = {StartPos, current};
25+
Color c = new Color(252, 253, 189);
26+
27+
l.startWidth = height;
28+
l.endWidth = height;
29+
l.SetPositions(pos);
30+
//l.startColor = c;
31+
//l.endColor = c;
32+
l.useWorldSpace = true;
33+
}
1734
}
1835
}

Assets/Line.prefab

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ GameObject:
99
serializedVersion: 6
1010
m_Component:
1111
- component: {fileID: 1945975318650849095}
12-
- component: {fileID: 1945975318650849094}
13-
- component: {fileID: 863930387729394175}
12+
- component: {fileID: 1609963738480068943}
13+
- component: {fileID: -558291657561903659}
1414
m_Layer: 0
1515
m_Name: Line
1616
m_TagString: Untagged
@@ -32,26 +32,26 @@ Transform:
3232
m_Father: {fileID: 0}
3333
m_RootOrder: 0
3434
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35-
--- !u!212 &1945975318650849094
36-
SpriteRenderer:
35+
--- !u!120 &1609963738480068943
36+
LineRenderer:
3737
m_ObjectHideFlags: 0
3838
m_CorrespondingSourceObject: {fileID: 0}
3939
m_PrefabInstance: {fileID: 0}
4040
m_PrefabAsset: {fileID: 0}
4141
m_GameObject: {fileID: 1945975318650849093}
4242
m_Enabled: 1
43-
m_CastShadows: 0
44-
m_ReceiveShadows: 0
43+
m_CastShadows: 1
44+
m_ReceiveShadows: 1
4545
m_DynamicOccludee: 1
46-
m_MotionVectors: 1
47-
m_LightProbeUsage: 1
48-
m_ReflectionProbeUsage: 1
46+
m_MotionVectors: 0
47+
m_LightProbeUsage: 0
48+
m_ReflectionProbeUsage: 0
4949
m_RayTracingMode: 0
5050
m_RayTraceProcedural: 0
5151
m_RenderingLayerMask: 1
5252
m_RendererPriority: 0
5353
m_Materials:
54-
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
54+
- {fileID: 10306, guid: 0000000000000000f000000000000000, type: 0}
5555
m_StaticBatchInfo:
5656
firstSubMesh: 0
5757
subMeshCount: 0
@@ -64,26 +64,73 @@ SpriteRenderer:
6464
m_IgnoreNormalsForChartDetection: 0
6565
m_ImportantGI: 0
6666
m_StitchLightmapSeams: 1
67-
m_SelectedEditorRenderState: 0
67+
m_SelectedEditorRenderState: 3
6868
m_MinimumChartSize: 4
6969
m_AutoUVMaxDistance: 0.5
7070
m_AutoUVMaxAngle: 89
7171
m_LightmapParameters: {fileID: 0}
7272
m_SortingLayerID: 0
7373
m_SortingLayer: 0
7474
m_SortingOrder: 0
75-
m_Sprite: {fileID: 21300000, guid: 0ea588bedf09ef24ab2a1343271e4bfd, type: 3}
76-
m_Color: {r: 1, g: 1, b: 1, a: 1}
77-
m_FlipX: 0
78-
m_FlipY: 0
79-
m_DrawMode: 0
80-
m_Size: {x: 0.42, y: 0.42}
81-
m_AdaptiveModeThreshold: 0.5
82-
m_SpriteTileMode: 0
83-
m_WasSpriteAssigned: 1
84-
m_MaskInteraction: 0
85-
m_SpriteSortPoint: 0
86-
--- !u!114 &863930387729394175
75+
m_Positions:
76+
- {x: 0, y: 0, z: 0}
77+
- {x: 0, y: 0, z: 1}
78+
m_Parameters:
79+
serializedVersion: 3
80+
widthMultiplier: 1
81+
widthCurve:
82+
serializedVersion: 2
83+
m_Curve:
84+
- serializedVersion: 3
85+
time: 0
86+
value: 1
87+
inSlope: 0
88+
outSlope: 0
89+
tangentMode: 0
90+
weightedMode: 0
91+
inWeight: 0.33333334
92+
outWeight: 0.33333334
93+
m_PreInfinity: 2
94+
m_PostInfinity: 2
95+
m_RotationOrder: 4
96+
colorGradient:
97+
serializedVersion: 2
98+
key0: {r: 0.9921569, g: 0.9921569, b: 0.75294125, a: 1}
99+
key1: {r: 0.9921569, g: 0.9921569, b: 0.75294125, a: 1}
100+
key2: {r: 0, g: 0, b: 0, a: 0}
101+
key3: {r: 0, g: 0, b: 0, a: 0}
102+
key4: {r: 0, g: 0, b: 0, a: 0}
103+
key5: {r: 0, g: 0, b: 0, a: 0}
104+
key6: {r: 0, g: 0, b: 0, a: 0}
105+
key7: {r: 0, g: 0, b: 0, a: 0}
106+
ctime0: 0
107+
ctime1: 65535
108+
ctime2: 0
109+
ctime3: 0
110+
ctime4: 0
111+
ctime5: 0
112+
ctime6: 0
113+
ctime7: 0
114+
atime0: 0
115+
atime1: 65535
116+
atime2: 0
117+
atime3: 0
118+
atime4: 0
119+
atime5: 0
120+
atime6: 0
121+
atime7: 0
122+
m_Mode: 0
123+
m_NumColorKeys: 2
124+
m_NumAlphaKeys: 2
125+
numCornerVertices: 0
126+
numCapVertices: 0
127+
alignment: 0
128+
textureMode: 0
129+
shadowBias: 0.5
130+
generateLightingData: 0
131+
m_UseWorldSpace: 1
132+
m_Loop: 0
133+
--- !u!114 &-558291657561903659
87134
MonoBehaviour:
88135
m_ObjectHideFlags: 0
89136
m_CorrespondingSourceObject: {fileID: 0}
@@ -95,3 +142,4 @@ MonoBehaviour:
95142
m_Script: {fileID: 11500000, guid: 913387855c96efd43b84aad41e2587c9, type: 3}
96143
m_Name:
97144
m_EditorClassIdentifier:
145+
height: 0.1

0 commit comments

Comments
 (0)