Gravity Portals addet
This commit is contained in:
@@ -13,6 +13,7 @@ public class BlockScript : MonoBehaviour
|
||||
private Vector3 rotation;
|
||||
private float speed = 175;
|
||||
public bool IsFlying = false;
|
||||
public int gravity = 2;
|
||||
|
||||
private UnityEngine.RigidbodyConstraints2D constraints;
|
||||
|
||||
@@ -26,7 +27,7 @@ public class BlockScript : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
if (!logic.IsFreezed) {
|
||||
m_Rigidbody.gravityScale = 2;
|
||||
m_Rigidbody.gravityScale = gravity;
|
||||
m_Rigidbody.constraints = RigidbodyConstraints2D.None;
|
||||
logic.addTime();
|
||||
}
|
||||
@@ -45,7 +46,7 @@ public class BlockScript : MonoBehaviour
|
||||
if(logic.IsFreezed) {
|
||||
velocity = m_Rigidbody.velocity;
|
||||
m_Rigidbody.velocity = Vector2.zero;
|
||||
m_Rigidbody.gravityScale = 0;
|
||||
gravity = 0;
|
||||
m_Rigidbody.constraints = RigidbodyConstraints2D.FreezeRotation;
|
||||
}
|
||||
|
||||
@@ -72,12 +73,7 @@ public class BlockScript : MonoBehaviour
|
||||
IsFlying = true;
|
||||
m_Rigidbody.velocity = Vector2.up * 17;
|
||||
}
|
||||
|
||||
if (collision.gameObject.layer==10) {
|
||||
IsFlying = false;
|
||||
rotation = Vector3.back;
|
||||
transform.Rotate(rotation * speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collider) {
|
||||
@@ -86,6 +82,15 @@ public class BlockScript : MonoBehaviour
|
||||
rotation = Vector3.back;
|
||||
transform.Rotate(rotation * speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (collider.gameObject.layer==11) {
|
||||
if (collider.gameObject.GetComponent<Gravity_Reverse_Portal_Script>().direction==0) {
|
||||
gravity = -2;
|
||||
}
|
||||
else if(collider.gameObject.GetComponent<Gravity_Reverse_Portal_Script>().direction==1){
|
||||
gravity = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerStay2D(Collider2D collider) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Gravity_Reverse_Portal_Script : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 5;
|
||||
public float deadZone = -15;
|
||||
public BlockScript player;
|
||||
|
||||
public LogicScript logic;
|
||||
//0 means from right to false
|
||||
//1 means from false to right
|
||||
public int direction;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player").GetComponent<BlockScript>();
|
||||
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (player.IsAlive&&!logic.IsFreezed) {
|
||||
transform.position = transform.position + (Vector3.left * moveSpeed) * Time.deltaTime;
|
||||
}
|
||||
|
||||
if(transform.position.x<deadZone){
|
||||
Debug.Log("Portal Deleted");
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collider) {
|
||||
if (collider.gameObject.layer==3) {
|
||||
Debug.Log("Player On Me");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca92f5ae2cc37cf47ba62f60159ee2a3
|
||||
@@ -81,7 +81,7 @@ public class LogicScript : MonoBehaviour
|
||||
bgscript.ScrollSpeed = 1f;
|
||||
audioManager.PlayMusic();
|
||||
player.m_Rigidbody.velocity = player.velocity;
|
||||
|
||||
player.gravity = 2;
|
||||
}
|
||||
|
||||
public void ExitGame() {
|
||||
|
||||
Reference in New Issue
Block a user