This commit is contained in:
DerTyp187
2021-10-01 21:28:28 +02:00
parent 86dc271305
commit 7345c34537
4 changed files with 64 additions and 56 deletions

View File

@@ -580,7 +580,7 @@ GameObject:
- component: {fileID: 708126141}
- component: {fileID: 708126140}
m_Layer: 5
m_Name: Canvas
m_Name: HUD
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -1676,7 +1676,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3}
propertyPath: jumpForce
value: 3.5
value: 4
objectReference: {fileID: 0}
- target: {fileID: 8390537188327133020, guid: 6a86db7765f277243b912c20f451dc47, type: 3}
propertyPath: jumpHeight
@@ -1710,6 +1710,10 @@ PrefabInstance:
propertyPath: m_Name
value: FirstPerson Player
objectReference: {fileID: 0}
- target: {fileID: 8390537188327133021, guid: 6a86db7765f277243b912c20f451dc47, type: 3}
propertyPath: m_TagString
value: FPSPlayer
objectReference: {fileID: 0}
- target: {fileID: 8390537188327133022, guid: 6a86db7765f277243b912c20f451dc47, type: 3}
propertyPath: m_RootOrder
value: 1

View File

@@ -5,7 +5,6 @@ using UnityEngine;
public abstract class BuildingBlueprint : MonoBehaviour
{
public bool isColliding;
public bool followMouse = true;
public GameObject constructionPrefab;
private GameObject terrain;
@@ -20,67 +19,31 @@ public abstract class BuildingBlueprint : MonoBehaviour
private void Start()
{
hud = GameObject.Find("HUD").GetComponent<Canvas>();
hud = GameObject.Find("HUD").GetComponent<Canvas>(); //Get HUD Canvas
terrain = GameObject.FindGameObjectWithTag("Terrain"); //Get Terrain
//Bug Fix Blueprints already existing
//Delete/CleanUp all objs with tag "Blueprint"
GameObject[] blueprints = GameObject.FindGameObjectsWithTag("Blueprint");
foreach (GameObject blueprint in blueprints)
Destroy(blueprint);
gameObject.tag = "Blueprint";
gameObject.tag = "Blueprint"; //Give Gameobject the tag "Blueprint" (after deleting all objs with this tag)
terrain = GameObject.FindGameObjectWithTag("Terrain");
hud.enabled = false;
hud.enabled = false; //Hide HUD
Init();
Init(); //Call init callback function for children
}
//Collision
public void OnCollisionEnter(Collision collision)
{
isColliding = true;
Debug.Log("Colliding True");
}
public void OnCollisionStay(Collision collision)
{
isColliding = true;
Debug.Log("Colliding True");
}
public void OnCollisionExit(Collision collision)
{
isColliding = false;
Debug.Log("Colliding False");
}
//Placing
public void Update()
{
if (followMouse)
{
//Following Mouse
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitData;
if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity))
{
transform.position = hitData.point;
}
}
if (Input.GetMouseButtonDown(0) && !isColliding)
{
Instantiate(constructionPrefab, transform.position, transform.rotation);
Destroy(this.gameObject);
hud.enabled = true;
}
FollowMouse();
Rotate();
//Collinding Callbacks
if (isColliding)
{
{
WhileColliding();
}
else
@@ -88,15 +51,32 @@ public abstract class BuildingBlueprint : MonoBehaviour
WhileNotColliding();
}
//PLACE
if (Input.GetMouseButtonDown(0) && !isColliding)
{
Place();
}
}
//Rotate
void FollowMouse()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitData;
if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity))
{
transform.position = hitData.point;
}
}
void Rotate()
{
if (Input.GetButtonDown("Rotate"))
{
Debug.Log("Rotate+");
if (Input.GetKey(KeyCode.LeftShift))
{
transform.Rotate(0, 5, 0);
}else if (Input.GetKey(KeyCode.LeftControl))
}
else if (Input.GetKey(KeyCode.LeftControl))
{
transform.Rotate(0, 45, 0);
}
@@ -104,7 +84,7 @@ public abstract class BuildingBlueprint : MonoBehaviour
{
transform.Rotate(0, 22.5f, 0);
}
}
if (Input.GetButtonDown("CounterRotate"))
@@ -113,7 +93,8 @@ public abstract class BuildingBlueprint : MonoBehaviour
if (Input.GetKey(KeyCode.LeftShift))
{
transform.Rotate(0, -5, 0);
}else if (Input.GetKey(KeyCode.LeftControl))
}
else if (Input.GetKey(KeyCode.LeftControl))
{
transform.Rotate(0, -45, 0);
}
@@ -123,8 +104,30 @@ public abstract class BuildingBlueprint : MonoBehaviour
}
}
}
void Place()
{
Instantiate(constructionPrefab, transform.position, transform.rotation);
Destroy(this.gameObject);
hud.enabled = true;
}
//Collision
public void OnCollisionEnter(Collision c)
{
isColliding = true;
Debug.Log("Colliding True");
}
public void OnCollisionStay(Collision c)
{
isColliding = true;
Debug.Log("Colliding True");
}
public void OnCollisionExit(Collision c)
{
isColliding = false;
Debug.Log("Colliding False");
}
}

View File

@@ -362,7 +362,7 @@ InputManager:
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: r
positiveButton: x
altNegativeButton:
altPositiveButton:
gravity: 1000
@@ -378,7 +378,7 @@ InputManager:
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: q
positiveButton: y
altNegativeButton:
altPositiveButton:
gravity: 1000

View File

@@ -10,6 +10,7 @@ TagManager:
- Terrain
- Blueprint
- StorageBuilding
- FPSPlayer
layers:
- Default
- TransparentFX