Scripting trouble, Float on Collision/collision open gate
I am working on my first unity scene and I want to make an object float up when it is bumped into. I know how to write a script to make it float but not when its collided with. I also want to make a gate when opens when the avatar walks into it. I am fairly new at scripting and have been trying combine a collision code with my float but it isnt working. I know a code that will make it change colors upon collision but taking that to what I want with float is proving harder than I thought. Any suggestions or help would be greatly appreciated.
Answer by Kitiarafox · Apr 30, 2016 at 01:08 AM
I have not tried that yet but found a code idea for the door dealing with triggers. Triggers are new for me. I had a brief video show collision changing objects color and making one thing rocket up and keep going up forever but I want to try a trigger float but not sure how to. Scripting is something new to me and I want to figure it out.
Answer by AlbinoStoic · Apr 30, 2016 at 01:12 AM
Basically instead of OnCollisionEnter you can use OnTriggerEnter
OnCollisionStay OnTriggerStay
etc.
I tried this code for the gate opening but on the page showing how to this it says pull door which is my gate into the gate/door spot on the script area of the button but it has no option like this site shows. Site: http://videogamedesign24.com/tutorial-opening-doors-using-buttons-triggers-in-unity/ Code:
using UnityEngine; using System.Collections;
public class Door : $$anonymous$$onoBehaviour { public Vector3 OpenPosition; private bool open;
public IEnumerator OpenUp ()
{
if (!open)
{
while (transform.position != OpenPosition)
{
transform.position = Vector3.$$anonymous$$oveTowards(transform.position, OpenPosition, 0.25f);
if (Vector3.Distance(transform.position, OpenPosition) <= 0.25f)
{
transform.position = OpenPosition;
open = true;
}
yield return null;
}
}
}
}
and
using UnityEngine; using System.Collections;
public class TriggerButton : $$anonymous$$onoBehaviour { public GameObject Door;
void OnTriggerEnter (Collider collider)
{
if (collider.gameObject.tag == "Player")
StartCoroutine(Door.GetComponent().OpenUp());
}
}
now as for the float trigger I am lost on how to write it. I am thinking i could do something lke the trigger above to rotate but my brain is missing the dots to connect them. I am just starting script codes. Forgive my lack of understanding, I am new to all this.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075827im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Detect overlapping objects 2D game 0 Answers