- Home /
Duplicate Question
How to create timer when selecting and deselecting items
I'm completely stumped with this current task, essentially, what i'm trying to do is. While i'm colliding over one item for more than 3 seconds i wish to pick it up. Then when to deselect, while i collide with another object wait three seconds to deselect it. This seems so easy when i type it but i'm not having any luck what so ever. I can select items fine, and when i do i have a script to highlight it in a different color, however when i wish to deselect it does it immediately without waiting hope this makes sense
void OnCollisionStay(Collision Other)
{
//Debug.Log("the start time" + startTime + "the boolean"+ stool.pickedUP);
if(Other.gameObject.GetComponent(typeof(TextControl)))
{
startTime+=Time.deltaTime;
roundedRestSecounds=Mathf.CeilToInt(Time.time);
progress = startTime *0.2f;
CurrentState=true;
}
else if(Other.collider.tag==("Organ")){
startTime+=Time.deltaTime;
progress = startTime *0.5f;
if(startTime>2.8f){
stool.gameObject.BroadcastMessage("PickUP",Other.gameObject.name);
//send message to deselect
//or pick up = false
//have plaeable here
}//the only way we can test for colliding with something else is by checking if the last is the current
if(stool.lastSelectedTool.name!=Other.gameObject.name){
changeTime+=Time.deltaTime;
if(changeTime>2.8f){
stool.gameObject.BroadcastMessage("PlacedDown",Other.gameObject.name);
}
}
}
/*
else if(Other.collider.tag==("Placeable")){
if(!stool.pickedUP){
}
if(stool.pickedUP)
{
progress = startTime *0.5f;
//if start eceeds certain number
if(startTime>6.0f)
{
stool.putDown();
}
//you coud from this point send a message
}
}*/
else{
}
}
Above is my collider withing my player class, this works fine with regards to selecting an item, however when i want to place it places it down immeidiatly. This is probably due to the face that changetime doesn't change back to 0 unless you exit the collision. could someone please help in getting my timer working correctly
void OnCollisionExit(Collision Other){
startTime =0f;
progress =0f;
changeTime=0f;
}
thousands of excellent questions on here about timers, search Invoke() etc. also unityGE$$anonymous$$S.com
Follow this Question
Related Questions
Comparing two GameObjects to pick up items 1 Answer
Custom Cursor with Kinect Wrapper 1 Answer
Kinect Hand Smoothing 0 Answers
How To Assign An Animation When Firing Weapon? 1 Answer
pause for dastardly bannana 1 Answer