Fixed drawing
This commit is contained in:
@@ -6,7 +6,7 @@ using UnityEngine.EventSystems;
|
||||
public class Drawer : MonoBehaviour
|
||||
{
|
||||
public LineRenderer lineRenderer;
|
||||
public EdgeCollider2D edgeCollider2D;
|
||||
public PolygonCollider2D edgeCollider2D;
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
|
||||
|
||||
@@ -20,14 +20,25 @@ public class Drawer : MonoBehaviour
|
||||
points = new List<Vector3>();
|
||||
|
||||
|
||||
// lineRenderer.transform.position = new Vector3(0, 0, 10);
|
||||
//lineRenderer.GetComponent<Rigidbody2D>().simulated = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vector3 startedPoint = new Vector3();
|
||||
public void OnMouseDrag(BaseEventData e) {
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
Vector3 worldPos = Camera.main.ScreenToWorldPoint(ped.position);
|
||||
if(points.Count> 0) {
|
||||
RaycastHit2D hit = Physics2D.Linecast(points[points.Count - 1], worldPos);
|
||||
if (hit.collider != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
points.Add(Camera.main.ScreenToWorldPoint(ped.position));
|
||||
points.Add(worldPos);
|
||||
UpdateLine();
|
||||
}
|
||||
|
||||
@@ -54,7 +65,12 @@ public class Drawer : MonoBehaviour
|
||||
{
|
||||
points3.Add(point);
|
||||
}
|
||||
edgeCollider2D.SetPoints(points3);
|
||||
for(int i= points.Count-1; i >0; i--)
|
||||
{
|
||||
points3.Add(points[i] + new Vector3(0,0.1f,0));
|
||||
}
|
||||
//edgeCollider2D.SetPoints(points3);
|
||||
edgeCollider2D.SetPath(0, points3);
|
||||
edgeCollider2D.GetComponent<Rigidbody2D>().simulated = true;
|
||||
}
|
||||
|
||||
@@ -62,7 +78,7 @@ public class Drawer : MonoBehaviour
|
||||
{
|
||||
if (edgeCollider2D == null)
|
||||
{
|
||||
edgeCollider2D = lineRenderer.GetComponent<EdgeCollider2D>();
|
||||
edgeCollider2D = lineRenderer.GetComponent<PolygonCollider2D>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
Assets/Scripts/Enemy.cs
Normal file
14
Assets/Scripts/Enemy.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Enemy : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 0.1f;
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (GameManager.Player == null) { return; }
|
||||
|
||||
transform.Translate((GameManager.Player.position - transform.position).normalized * moveSpeed);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Enemy.cs.meta
Normal file
11
Assets/Scripts/Enemy.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a515e7c6c1edfdd44a449609cf5191e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/GameManager.cs
Normal file
25
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public Transform player;
|
||||
public static Transform Player { get { if (instance == null) { return null; } return instance.player; } }
|
||||
|
||||
public static GameManager instance { get;private set; }
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager.cs.meta
Normal file
11
Assets/Scripts/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2f7f662bf5cf054bafc6df165d07f7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user