mirror of
https://github.com/DerTyp7/traffic-unity.git
synced 2025-11-01 14:12:29 +01:00
place streets
This commit is contained in:
38
Assets/Scripts/PlaceableObject.cs
Normal file
38
Assets/Scripts/PlaceableObject.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlaceableObject : MonoBehaviour
|
||||
{
|
||||
public GameObject childObject;
|
||||
public bool placeable = true;
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
ScaleOnMousePosition();
|
||||
RotateToMousePosition();
|
||||
|
||||
placeable = childObject.GetComponent<PlaceableObjectChild>().placeable;
|
||||
}
|
||||
|
||||
float AngleBetweenTwoPoints(Vector3 a, Vector3 b)
|
||||
{
|
||||
return Mathf.Atan2(a.y - b.y, a.x - b.x) * Mathf.Rad2Deg;
|
||||
}
|
||||
|
||||
void RotateToMousePosition()
|
||||
{
|
||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
mousePosition.z = 0;
|
||||
float angle = AngleBetweenTwoPoints(transform.position, mousePosition);
|
||||
transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
|
||||
}
|
||||
void ScaleOnMousePosition()
|
||||
{
|
||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
mousePosition.z = 0;
|
||||
|
||||
transform.localScale = new Vector3(-Vector3.Distance(mousePosition, transform.position), 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user