Well this is my script (Well part of it, the script itself is too big)
RaycastHit Hit;
if (Physics.Raycast(PlayerCamera.position, PlayerCamera.forward, out Hit, 2)){
if (Hit.collider.gameObject.tag == “soda”)
{
showMessage = true;
if(Input.GetKeyDown(“f”) Time.time > nextPress)
{
thirst += sodacan;
Destroy(Hit.collider.gameObject);
showMessage = false;
}
}
if (Hit.collider.gameObject.tag == “water”)
{
showMessage = true;
if(Input.GetKeyDown(“f”) Time.time > nextPress)
{
thirst += water;
Destroy(Hit.collider.gameObject);
showMessage = false;
}
}
if (Hit.collider.gameObject.tag == “foodcan”)
{
showMessage = true;
if(Input.GetKeyDown(“f”) Time.time > nextPress)
{
hunger += cannedfood;
thirst -= 5;
Destroy(Hit.collider.gameObject);
showMessage = false;
}
}
if(!Hit.collider){
showMessage = false;
}
if(hit.collider.tag == “untagged”)
{
showMessage = false;
}
}
When I am near the object and I’m pointing at it, no message appears, and I can’t pick it, some help please?
So, first off, be sure to put your script in the correct formatting when posting. You’ll see a button with a “#” sign. just select your text and hit that, your formatting will be much more readable.
There’s a few things here, but there really isn’t enough of your material here for me to tell if it really is the issue. The first thing I can definitely see is your call to Time.time. It’s hard for me to know why your message isn’t showing, because the code for “if(showMessage){}” isn’t anywhere in your post.
Time.time is the time since the game started, so currently the way you have it set up, Time.time will always be greater than nextPress. So, you’ll want something like this to make it so that you can only press x amount of times per second. Note that this is in UnityScript, so you’ll have to do some simple translating…it isn’t very complex.
var nextPress : float; //update this with the next time we can press again
var buttonTime : float = 0.5 //we can press once every 0.5 seconds
if(Input.GetKeyDown("f") Time.time>nextPress){
DoStuff();
nextPress = Time.time + buttonTime;
}
To figure out what’s actually going on, print different things at points in your code with Debug.Log to figure out how far your code can get, if you actually are getting the collider with the soda can, if your button presses are set up right. That way you can figure out exactly where your code is going wrong…good luck
Ok I did the cooldown thing.
And here I will put all the parts if you need something else tell me.
//Hunger and Thirst
public float hunger = 100f;
public float maxhunger = 100f;
public float thirst = 100f;
public float maxthirst = 100f;
public float sodacan = 25;
public float cannedfood = 50;
public float water = 45;
public float pickupCD = 0.5f;
void start()
{
hunger = maxhunger;
thirst = maxthirst;
}
public void HungerThirst()
{
if(hunger > 100)
hunger = 100;
if(hunger < 0)
hunger = 0;
hunger -= 0.01f * Time.deltaTime;
if(thirst > 100)
thirst = 100;
if(thirst < 0)
thirst = 0;
thirst -= 0.02f * Time.deltaTime;
if(hunger == 0 || thirst ==0)
currentHealth -= 0.1f * Time.deltaTime;
}
And I think that's all