Hello! What I want to do is when my character floats to the right and collides with an invisible mesh, I want the player to fall down if the mouse button isn’t pressed but if it is pressed while it’s colliding it should continue to hover to the right!
I have done the hovering to the right script and I can’t do the thing with the falling. Help plox?
I managed to fix it! I’m gonna leave the scripts here in case someone else has my problem.
Falling Code.
using UnityEngine;
using System.Collections;
public class Fall : MonoBehaviour {
public Collider coll;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay(Collider other) {
if (!Input.GetButton("Fire1"))
{
other.attachedRigidbody.useGravity = true;
other.GetComponent<Hover>().enabled = false;
}
else
{
other.attachedRigidbody.useGravity = false;
other.GetComponent<Hover>().enabled = true;
}
}
}
Hover Code
public class Hover : MonoBehaviour {
public float horizontalSpeed;
public float verticalSpeed;
public float amptitude;
public Vector3 tempPosition;
void Start ()
{
tempPosition = transform.position;
}
void Update ()
{
tempPosition.x += horizontalSpeed;
tempPosition.y = Mathf.Sin (Time.realtimeSinceStartup * verticalSpeed) * amptitude;
transform.position = tempPosition;
}
}