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

Need Help again

Discussion in 'Getting Started' started by Gromis, Jan 21, 2015.

  1. Gromis

    Gromis

    Joined:
    Dec 15, 2014
    Posts:
    7
    Yo guys !!!!
    How's your day ? My day is really good !
    Today am on the end of finishing my first game (i'm new in unity)
    and i have few bugs which i tried to fix myself but with no succes.
    I created a video for showing all the bugs i will link the video at the end.
    So the few bugs i get the ball speed goes really fast and its impossible to try to block it,second bug is that when the ball hits the goal it doesnt respawn and he needs to go in oposite direction,the third is that in different resolution scale main camera size changes which reveals the game underborders(what is behined borders).
    MY SCRIPTS:

    GOAL SCRIPT:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEngine.UI;
    5. public class GoalScript : MonoBehaviour {
    6.     public int attackingPlayer;
    7.     public GameManagerScript gameMan;
    8.     void OnCollisionEnter2D(Collision2D other)
    9.     {
    10.         if(other.transform.name == "Ball")
    11.         {
    12.             gameMan.GoalScored(attackingPlayer);
    13.         }
    14.     }
    15. }
    16.  
    GameManagerScript:

    Code (CSharp):
    1. using UnityEngine.UI;
    2. using System.Collections;
    3. using UnityEngine;
    4. public class GameManagerScript:MonoBehaviour{
    5.     // Use this for initialization
    6.     public int playerOneScore, playerTwoScore;
    7.     public Text scoreText;
    8.     public BallScript gameBall;
    9.     void Start () {
    10.         playerOneScore = 0;
    11.         playerTwoScore = 0;
    12.     }
    13.     public void GoalScored(int playerNumber)
    14.     {
    15.         // increase the score for whichever player scored
    16.         if(playerNumber == 1)
    17.             playerOneScore++;
    18.         else if (playerNumber ==2)
    19.             playerTwoScore++;
    20.      
    21.         // now check if the player has won
    22.         if (playerOneScore == 3)
    23.                         Application.LoadLevel (2);
    24.                 else if (playerTwoScore == 3)
    25.                         Application.LoadLevel (3);
    26.         UpdateScoreText();
    27.     }
    28.     public void GameOver(int winner)
    29.     {
    30.         // this is called when a player reaches 3 points
    31.      
    32.         // reset the scores
    33.         playerOneScore = 0;
    34.         playerTwoScore = 0;
    35.         gameBall.Reset ();
    36.         UpdateScoreText();
    37.     }
    38.     void UpdateScoreText()
    39.     {
    40.         scoreText.text = "Player One " + playerOneScore.ToString() + " - " + playerTwoScore.ToString() + " Player Two";
    41.     }
    42. }
    43.  
    PaddleScript:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class PaddleScript : MonoBehaviour {
    4.  
    5.     [SerializeField]
    6.     bool isPlayerTwo;
    7.     [SerializeField]
    8.     float speed = 0.2f;       // how far the paddle moves per frame
    9.     Transform myTransform;    // reference to the object's transform
    10.     int direction = 0; // 0 = still, 1= up, -1 = down
    11.     float previousPositionY;
    12.     // Use this for initialization
    13.     void Start () {
    14.         myTransform = transform;
    15.         previousPositionY = myTransform.position.y;
    16.     }
    17.  
    18.     // FixedUpdate is called once per physics tick/frame
    19.     void FixedUpdate () {
    20.         // first decide if this is player 1 or player 2 so we know what keys to listen for
    21.         if (isPlayerTwo)
    22.         {
    23.             if (Input.GetKey ("w"))
    24.                 MoveUp ();
    25.             else if (Input.GetKey ("s"))
    26.                 MoveDown ();
    27.         }
    28.         else // if not player 2 it must be player 1
    29.         {
    30.             if (Input.GetKey ("o"))
    31.                 MoveUp ();
    32.             else if (Input.GetKey ("l"))
    33.                 MoveDown ();
    34.         }
    35.         if (previousPositionY > myTransform.position.y)
    36.             direction = -1;
    37.         else if (previousPositionY < myTransform.position.y)
    38.             direction =1;
    39.         else
    40.             direction = 0;
    41.     }
    42.  
    43.     // move the player's paddle up by an amount determined by 'speed'
    44.     void MoveUp()
    45.     {
    46.         myTransform.position = new Vector2(myTransform.position.x, myTransform.position.y + speed);
    47.     }
    48.  
    49.     // move the player's paddle down by an amount determined by 'speed'
    50.     void MoveDown()
    51.     {
    52.         myTransform.position = new Vector2 (myTransform.position.x, myTransform.position.y - speed);        
    53.     }
    54.     void LateUpdate()
    55.     {
    56.         previousPositionY = myTransform.position.y;
    57.     }
    58.     void OnCollisionExit2D(Collision2D other)
    59.     {
    60.         float adjust = 5 * direction;
    61.         other.rigidbody.velocity = new Vector2(other.rigidbody.velocity.x, other.rigidbody.velocity.y + adjust);    
    62.     }
    63. }
    If you need more just watch the video i showed it all and introduce the game how it will work :)
     
  2. Gromis

    Gromis

    Joined:
    Dec 15, 2014
    Posts:
    7
  3. Mikenseer

    Mikenseer

    Joined:
    Jul 24, 2012
    Posts:
    74
    Not seeing the video buddy.
     
  4. DustyMcp

    DustyMcp

    Joined:
    May 23, 2013
    Posts:
    25
    no video