|
@ -27,9 +27,11 @@ public class magnetGun : MonoBehaviour { |
|
|
public float maxPullSpeed = 30; |
|
|
public float maxPullSpeed = 30; |
|
|
public float rotateSpeed; |
|
|
public float rotateSpeed; |
|
|
public float minDistance = 3.0f; |
|
|
public float minDistance = 3.0f; |
|
|
|
|
|
public float impulsePower = 50.0f; |
|
|
|
|
|
|
|
|
private float maxWalkSpeed; |
|
|
private float maxWalkSpeed; |
|
|
|
|
|
|
|
|
|
|
|
private Renderer lastTargetRenderer; |
|
|
|
|
|
private Color lastTargetColour; |
|
|
// Use this for initialization
|
|
|
// Use this for initialization
|
|
|
void Start () { |
|
|
void Start () { |
|
|
if (topScreen) |
|
|
if (topScreen) |
|
@ -56,9 +58,14 @@ public class magnetGun : MonoBehaviour { |
|
|
if (target.GetComponent<Collider>().tag == "moveable"){ |
|
|
if (target.GetComponent<Collider>().tag == "moveable"){ |
|
|
Debug.Log("Moveable Item"); |
|
|
Debug.Log("Moveable Item"); |
|
|
crossHair.GetComponent<RawImage>().color = Color.red; |
|
|
crossHair.GetComponent<RawImage>().color = Color.red; |
|
|
|
|
|
if (Vector3.Distance (rayHitPoint, camera.transform.position) <= minDistance) { |
|
|
|
|
|
crossHair.GetComponent<RawImage>().color = Color.blue; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateColors (target); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (triggerL > 0) { |
|
|
if (triggerL > 0) { |
|
@ -71,6 +78,7 @@ public class magnetGun : MonoBehaviour { |
|
|
dropItem(GravityTarget); |
|
|
dropItem(GravityTarget); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impulsePush (target); |
|
|
moveItem (GravityTarget); |
|
|
moveItem (GravityTarget); |
|
|
pullItem (triggerR); |
|
|
pullItem (triggerR); |
|
|
rotateInput (GravityTarget); |
|
|
rotateInput (GravityTarget); |
|
@ -86,7 +94,9 @@ public class magnetGun : MonoBehaviour { |
|
|
RaycastHit hit; |
|
|
RaycastHit hit; |
|
|
|
|
|
|
|
|
//Vector3 rayDirection = camera.transform.rotation * Vector3.forward;
|
|
|
//Vector3 rayDirection = camera.transform.rotation * Vector3.forward;
|
|
|
Ray ray = camera.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2 + (Screen.height/6 * playerScreen), 0)); |
|
|
|
|
|
|
|
|
//Ray ray = camera.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2 + (Screen.height/6 * playerScreen), 0));
|
|
|
|
|
|
|
|
|
|
|
|
Ray ray = camera.ScreenPointToRay(crossHair.transform.position); |
|
|
|
|
|
|
|
|
Debug.DrawRay (ray.origin, ray.direction*magnetRange, Color.green); |
|
|
Debug.DrawRay (ray.origin, ray.direction*magnetRange, Color.green); |
|
|
|
|
|
|
|
@ -94,6 +104,7 @@ public class magnetGun : MonoBehaviour { |
|
|
if (hit.collider.tag == "moveable"){ |
|
|
if (hit.collider.tag == "moveable"){ |
|
|
Debug.DrawRay (ray.origin,ray.direction*magnetRange, Color.red); |
|
|
Debug.DrawRay (ray.origin,ray.direction*magnetRange, Color.red); |
|
|
rayHitPoint = hit.point; |
|
|
rayHitPoint = hit.point; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -107,6 +118,9 @@ public class magnetGun : MonoBehaviour { |
|
|
item.attachedRigidbody.useGravity = false; |
|
|
item.attachedRigidbody.useGravity = false; |
|
|
item.attachedRigidbody.drag = 3.0f; |
|
|
item.attachedRigidbody.drag = 3.0f; |
|
|
item.attachedRigidbody.constraints = RigidbodyConstraints.FreezeRotation; |
|
|
item.attachedRigidbody.constraints = RigidbodyConstraints.FreezeRotation; |
|
|
|
|
|
//camera.transform.LookAt(item.transform.position);
|
|
|
|
|
|
//playerController.cameraX = camera.transform.eulerAngles.x;
|
|
|
|
|
|
//playerController.cameraY = camera.transform.eulerAngles.y;
|
|
|
gravityWell.transform.position = rayHitPoint; |
|
|
gravityWell.transform.position = rayHitPoint; |
|
|
GravityTarget = item; |
|
|
GravityTarget = item; |
|
|
targetOffset = GravityTarget.transform.position - rayHitPoint + (Vector3.up * 0.05f); |
|
|
targetOffset = GravityTarget.transform.position - rayHitPoint + (Vector3.up * 0.05f); |
|
@ -123,6 +137,16 @@ public class magnetGun : MonoBehaviour { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void impulsePush (Collider item){ |
|
|
|
|
|
if (item != null) { |
|
|
|
|
|
if (item.tag == "moveable" && Input.GetButtonDown("Quick Push")){ |
|
|
|
|
|
Vector3 direction = (transform.position - item.transform.position).normalized; |
|
|
|
|
|
|
|
|
|
|
|
item.attachedRigidbody.AddForce(direction * impulsePower * maxPullSpeed,ForceMode.Impulse); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void moveItem(Collider item){ |
|
|
private void moveItem(Collider item){ |
|
|
if (item != null) { |
|
|
if (item != null) { |
|
|
float step = objectSpeed * Time.deltaTime; |
|
|
float step = objectSpeed * Time.deltaTime; |
|
@ -206,5 +230,24 @@ public class magnetGun : MonoBehaviour { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void updateColors(Collider target){ |
|
|
|
|
|
|
|
|
|
|
|
if (target != null && target.tag == "moveable") { |
|
|
|
|
|
lastTargetRenderer = target.GetComponent<Renderer> (); |
|
|
|
|
|
|
|
|
|
|
|
if (lastTargetRenderer.material.color != Color.white) { |
|
|
|
|
|
lastTargetColour = lastTargetRenderer.material.color; |
|
|
|
|
|
lastTargetRenderer.material.color = Color.white; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
if (lastTargetRenderer != null) |
|
|
|
|
|
lastTargetRenderer.material.color = lastTargetColour; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |