Question: I would like help with a simple script for Unity 3d. I want to be able to have a trigger collision with a GameObject Circle.

I would like help with a simple script for Unity 3d. I want to be able to have a trigger collision with a GameObject Circle. When my player moves over the Circle an object with a light attached to it will rise up from the center of the circle. The light will turn on. I would like it to rise slowly. It can only be activated once. I have the general code working from a different script, I just can't seem to get it to go up, it goes horizontally.

onTriggerEnter(Collider other){

if (start position == false){ ObjectCloseTarget = object.localPosition;

ObjectOpenTarget = new Vector3( object.localPosition.x, object.localPosition.y + (sizeOfObjectInY * amountOfObjectInFloor), object.localPosition.z);

totalDistanceToCover = Vector3.Distance(ObjectCloseTarget, ObjectOpenTarget);

LiftObject();

float distanceCovered = (Time.time - startTime) * moveSpeed; float fractionDist = distanceCovered / totalDistanceToCover;

object.localPosition = Vector3.Lerp(object.localPosition, ObjectOpenTarget, fractionDist);

if (Mathf.Approximately(object.localPosition.y, objectOpenTarget.y)){

startPosition = true; //it has been activated switchLight.SetActive(true); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!