コード例 #1
0
ファイル: PongBall.cs プロジェクト: FloreauLuca/PingBongBR
    public void Respawn(int losePlayer)
    {
        if (losePlayer <= 0)
        {
            lastPosition  = transform.position;
            lastVelocity  = startForce;
            timeSinceLast = 0;
            GetComponent <Renderer>().material.color = GlobalGameManager.GetColor(lastPlayerID);
            Quaternion rotation = PongGameManager.CalculateCircleRotation(0, 0, PhotonNetwork.CurrentRoom.PlayerCount);
            photonView.RPC("AddForce", RpcTarget.All, lastPosition, rotation * startForce, losePlayer, true);
            return;
        }

        for (int i = 0; i < PhotonNetwork.CurrentRoom.PlayerCount; i++)
        {
            if (PhotonNetwork.PlayerList[i].ActorNumber == losePlayer)
            {
                float      radius   = 15f / Mathf.Tan(Mathf.PI / PhotonNetwork.CurrentRoom.PlayerCount);
                Quaternion rotation = PongGameManager.CalculateCircleRotation(0, i, PhotonNetwork.CurrentRoom.PlayerCount);
                Vector3    position = PongGameManager.CalculateCirclePosition(0, radius - 3, i, PhotonNetwork.CurrentRoom.PlayerCount);
                position += Vector3.up;
                photonView.RPC("AddForce", RpcTarget.All, position, rotation * startForce, losePlayer, true);
                break;
            }
        }
    }
コード例 #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.name == "Ball")
     {
         string wallName = transform.name;
         PongGameManager.Score(wallName);
         other.gameObject.SendMessage("RestartGame", 1.0f, SendMessageOptions.RequireReceiver);
     }
 }
コード例 #3
0
 void Awake()
 {
     if (_instance != null && _instance == this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
コード例 #4
0
 private void MakeSingleton()
 {
     if (Instance != null)
     {
         Destroy(Instance);
     }
     else
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
 }
コード例 #5
0
    private void Start()
    {
        rb     = GetComponent <Rigidbody2D>();
        circle = GetComponent <CircleCollider2D>();
        game   = FindObjectOfType <PongGameManager>();
        sr     = GetComponent <SpriteRenderer>();

        Vector3 dim = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));

        bound = new Vector2(dim.x - circle.radius, dim.y - circle.radius);
        //Debug.Log(bound);

        rb.velocity = Random.insideUnitCircle.normalized * speed;
        //rb.velocity = new Vector2(speed, 0);
    }
コード例 #6
0
    private void Awake()
    {
        if (main != null && main != this)
        {
            Destroy(gameObject);
            return;
        }

        main         = this;
        playerScores = new int[2];

        manager = World.DefaultGameObjectInjectionWorld.EntityManager;

        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);

        ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);

        oneSecond = new WaitForSeconds(1f);
        delay     = new WaitForSeconds(respawnDelay);

        StartCoroutine(CountdownAndSpawnBall());
    }
コード例 #7
0
 public void Awake()
 {
     Instance = this;
 }