开机不工作

时间:2016-03-22 16:11:39

标签: c++11 static-variables

所以我现在有一个工作'速度'上电,将玩家的速度乘以2.我正试图加强现在,这会增加你获得游戏对象'宝石'的分数2它应该从10增加到每颗宝石20点。

目前,上电是在10-20秒内在地图上随机产生的,如预期的那样,但是你收集上电所得的分数还没有达到20分。

PlayerMovement代码:

    public float speed = 10f;
private Rigidbody2D rb2d;
public GameObject Player;
public GameObject speedPowerUp;
public static int livess = 100;
public Vector2 movement;
public GameObject MultiPowerUp;
public static int addScore = 10;

void Start ()
{
    rb2d = GetComponent<Rigidbody2D> ();
}
void FixedUpdate () 
{
    float moveHorizontal = Input.GetAxis ("Horizontal"); //Gets keys that unity refers to being able to move horizontal (Set by default)
    float moveVertical = Input.GetAxis ("Vertical"); //Gets keys that unity refers to being able to move vertical (Set by default) Use forces to act with RigidBody2D
    Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
    rb2d.AddForce (movement * speed);
    if(moveHorizontal < 0)
        GetComponent<SpriteRenderer>().flipX = true;
    else if(moveHorizontal > 0)
        GetComponent<SpriteRenderer>().flipX = false;
}
void OnTriggerEnter2D(Collider2D other)
{
    if (other.gameObject.CompareTag ("shuriken")) 
    {
        if (livess <= 1) 
        {
            Destroy (Player);
            livess = livess - 1;
            Debug.LogError (livess);
        } 
        else 
        {
            livess = livess - 1;
            Debug.LogError (livess);
            return;
        }
    } 
    if (other.gameObject.CompareTag ("speedPowerUp")) 
    {
        StartCoroutine (WaitTimeSpeed ());
        other.gameObject.SetActive (false);
    }
    if (other.gameObject.CompareTag ("MultiPowerUp")) 
    {
        StartCoroutine (WaitTimeMulti ());
        other.gameObject.SetActive (false);
    }
}   
IEnumerator WaitTimeSpeed ()
{
    Debug.LogError (speed);
    speed = speed * 2;
    Debug.LogError (speed);
    yield return new WaitForSeconds (5);
    speed = speed / 2;
    Debug.LogError (speed);
    yield return new WaitForSeconds (Random.Range (10, 20));
    SpawnSpeed ();
}
void SpawnSpeed()
{
    Vector3 RandomSpawn = new Vector3 (Random.Range (-8.87F, 8.87F), Random.Range (-3.87F, 3.97F),1F);
    Instantiate (speedPowerUp, RandomSpawn, Quaternion.identity);
}
IEnumerator WaitTimeMulti()
{
    Debug.LogError (addScore);
    addScore = 20;
    Debug.LogError (addScore);
    yield return new WaitForSeconds (5);
    addScore = 10;
    yield return new WaitForSeconds (Random.Range (10, 20));
    SpawnMulti ();
}
void SpawnMulti ()
{
    Vector3 RandomSpawn = new Vector3 (Random.Range (-8.87F, 8.87F), Random.Range (-3.87F, 3.97F),1F);
    Instantiate (MultiPowerUp, RandomSpawn, Quaternion.identity);
}

}

宝石代码:

    public GameObject Gem;
public static int count;
public Text countText;
public int addScores = PlayerMovement.addScore;

void Start()
{
    SetCountText ();
}

void SpawnGem()
{
    Vector3 RandomSpawn = new Vector3 (Random.Range (-8.87F, 8.87F), Random.Range (-3.87F, 3.97F),1F);
    Instantiate (Gem, RandomSpawn, Quaternion.identity);
}
void OnTriggerEnter2D(Collider2D other)
{
    if (other.gameObject.CompareTag ("Player")) 
    {
        SpawnGem ();
        count = count + addScores;
        SetCountText ();
        PlayerPrefs.SetInt("Player Score", count); 
        Destroy (Gem);
    }
}
void SetCountText()
{
    countText.text = "Count: " + count.ToString ();
}

}

0 个答案:

没有答案