Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Camping

Discussion in 'Editor & General Support' started by joeynigro, May 23, 2019.

  1. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    How can I get the maximum sticks before the fire is active.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Code (csharp):
    1. public int MaximumSticks;
    2. private int currentSticks = 5;
    3.  
    4. public void CallBeforeFireIsActive()
    5. {
    6.     currentSticks = MaximumSticks;
    7. }
     
    Antypodish likes this.
  3. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    I use the fire as the goal and use the sticks as the pick up items.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    My same comment from your other thread about how you need to post some real content with your question applies here. My code example was a joke, since I have no idea what your sticks or fire are, how they are created, counted, etc, because you're for some reason unwilling to say basic things needed to understand the context of your question.
     
    Vryken and Antypodish like this.
  5. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    How about this for the sticks. What would the goal be for the fire.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Stick : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start ()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24.  
    25.     void OnTriggerEnter(Collider other)
    26.     {
    27.         if (other.gameObject.CompareTag ("Stick"))
    28.         {
    29.             other.gameObject.SetActive (false);
    30.         }
    31.     }
    32. }
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    You start threads with one liner. You need to learn how properly ask question, if you are not trolling. Go look around, how people do ask their questions and please learn this skill, if you want to be taken seriously.

    Your problem should be descriptive and informative. No lazy, as so far you have shown.
     
    Joe-Censored likes this.
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your question is about getting the maximum number of sticks before activating the fire, so the relevant code to post for your question would be:
    1) Wherever the maximum number of sticks is defined
    2) Whatever you use to track the current number of sticks
    3) Whatever code creates or gathers new sticks, and increases the count of sticks gathered
    4) Whatever code is called to activate the fire

    Also, you might want to explain why you have input/movement code within the Stick class itself, since your question implies there is more than 1 stick.