Fixed drawing

This commit is contained in:
2023-02-01 20:09:15 +05:30
parent 72a49a7973
commit 63d359793b
8 changed files with 485 additions and 20 deletions

View File

@@ -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
View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a515e7c6c1edfdd44a449609cf5191e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2f7f662bf5cf054bafc6df165d07f7a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: