Пример #1
0
    IEnumerator CompletePlayerLaunch()
    {
        yield return(new WaitForSeconds(0.1f));

        Debug.Log("FIRE!");
        GameObject projectileObj = Instantiate(
            GetProjectile(power),
            launchPoint.position,
            launchPoint.rotation,
            GameManager.Instance.WorldAnchor
            );

        Renderer projRenderer = projectileObj.GetComponent <Renderer>();

        projRenderer.material.color = PlayerColor;
        projRenderer.material.SetColor("_EmissionColor", PlayerColor);

        Projectile projectile = projectileObj.GetComponent <Projectile>();

        Vector3 launchVel =
            GameManager.Instance.WorldAnchor.InverseTransformDirection(launchPoint.forward * TotalPower);

        LauncherShot launcherShot = new LauncherShot("shot", this, projectileObj.transform.localPosition, launchVel);

        launcherShot.PowerSetting = power;
        Power = 0.0f;
        audioSource.PlayOneShot(launchSounds[Random.Range(0, launchSounds.Length)]);
        projectile.Launch(launcherShot);

        if (gameObject.tag.Equals("Player"))
        {
            GameManager.Instance.PlayerShot(launcherShot);
        }
    }
Пример #2
0
    public void Launch(LauncherShot newLauncherShot)
    {
        launcherShot = newLauncherShot;

        projectileCollider         = GetComponent <SphereCollider>();
        projectileCollider.enabled = true;
        gameManager  = GameManager.Instance;
        randomRot    = new Vector3(Random.value * 40, Random.value * 1, Random.value * 1);
        velocity     = launcherShot.Velocity;
        startPostion = launcherShot.StartPos;
        audioSource  = gameObject.AddComponent <AudioSource>();

        if (!launcherShot.IsReplay)
        {
            float   timeToImpact;
            Vector3 impactPos;
            launcherShot.DoesHit      = SimulateTrajectory(startPostion, velocity, out timeToImpact, out impactPos, false);
            launcherShot.TimeToImpact = timeToImpact;
            launcherShot.ImpactPos    = impactPos;
        }

        glow = Instantiate(gameManager.projectileGlowPrefab);
        glow.GetComponent <ProjectileGlow>().Init(transform);
        trail = GetComponent <TrailRenderer>();
    }
    public void AddShot(LauncherShot shot)
    {
        shot.Name = Mathf.FloorToInt(Time.time * 1000).ToString();

        DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("rooms/" + thisRoomNumber + "/shots/" + shot.Name);

        Debug.Log("Adding shot " + shot.Name + " from " + shot.Owner);
        reference.SetValueAsync(shot.GetData());
    }
Пример #4
0
    public void ForceLaunch(LauncherShot launcherShot)
    {
        Debug.Log(PlayerName + " is firing becuase of the networks!");

        GameObject projectileObj = Instantiate(
            GetProjectile(launcherShot.PowerSetting),
            launchPoint.position,
            launchPoint.rotation,
            GameManager.Instance.WorldAnchor
            );

        Renderer projRenderer = projectileObj.GetComponent <Renderer>();

        projRenderer.material.color = PlayerColor;
        projRenderer.material.SetColor("_EmissionColor", PlayerColor);

        Projectile projectile = projectileObj.GetComponent <Projectile>();

        launcherShot.IsReplay = true;
        audioSource.PlayOneShot(launchSounds[Random.Range(0, launchSounds.Length)]);
        projectile.Launch(launcherShot);
        hasFired = true;
    }
Пример #5
0
 public void EnemyShot(LauncherShot shot)
 {
     Debug.Log(shot.OwnerName + " took shot " + shot.Name);
     remoteLauncher.ForceLaunch(shot);
 }
Пример #6
0
 public void PlayerShot(LauncherShot shot)
 {
     multiplayer.AddShot(shot);
 }
    public void OnShotAdded(object sender2, ChildChangedEventArgs data)
    {
        Debug.Log("A new shot is added");

        if (data.Snapshot != null)
        {
            string shotName  = data.Snapshot.Child("name").Value.ToString();
            string shotOwner = data.Snapshot.Child("owner_name").Value.ToString();

            if (shotOwner.Equals(gameManager.LocalID))
            {
                Debug.Log("We already handled this!");
                return;
            }

            LauncherShot shot = new LauncherShot();
            shot.Name      = shotName;
            shot.OwnerName = shotOwner;
            shot.Owner     = gameManager.GetLauncher(shot.OwnerName);

            string timeToImpact = data.Snapshot.Child("time_to_impact").Value.ToString();
            shot.TimeToImpact = float.Parse(timeToImpact);

            string powerSettingString = data.Snapshot.Child("power_setting").Value.ToString();
            shot.PowerSetting = float.Parse(powerSettingString);

            string   startPosString = data.Snapshot.Child("start_pos").Value.ToString();
            string[] startPosArray  = startPosString.Split(',');
            Vector3  startPos       = new Vector3(
                float.Parse(startPosArray[0]),
                float.Parse(startPosArray[1]),
                float.Parse(startPosArray[2]));
            shot.StartPos = startPos;

            string   velocityString = data.Snapshot.Child("velocity").Value.ToString();
            string[] velocityArray  = velocityString.Split(',');
            Vector3  velocity       = new Vector3(
                float.Parse(velocityArray[0]),
                float.Parse(velocityArray[1]),
                float.Parse(velocityArray[2]));
            shot.Velocity = velocity;

            string   impactPosString = data.Snapshot.Child("impact_pos").Value.ToString();
            string[] impactArray     = impactPosString.Split(',');
            Vector3  impactPos       = new Vector3(
                float.Parse(impactArray[0]),
                float.Parse(impactArray[1]),
                float.Parse(impactArray[2]));
            shot.ImpactPos = impactPos;

            string doesHit = data.Snapshot.Child("does_hit").Value.ToString();
            shot.DoesHit = doesHit.Equals("true") ? true : false;
            string boardHit = data.Snapshot.Child("board_hit").Value.ToString();
            shot.BoardHit = boardHit.Equals("true") ? true : false;

            string hasDebris = data.Snapshot.Child("has_debris").Value.ToString();
            shot.HasDebris = hasDebris.Equals("true") ? true : false;

            shot.DebrisName = data.Snapshot.Child("debris_name").Value.ToString();

            string   debrisOffsetString = data.Snapshot.Child("debris_offset").Value.ToString();
            string[] debrisOffsetArray  = debrisOffsetString.Split(',');
            Vector3  debrisPos          = new Vector3(
                float.Parse(debrisOffsetArray[0]),
                float.Parse(debrisOffsetArray[1]),
                float.Parse(debrisOffsetArray[2]));
            shot.DebrisOffset = debrisPos;

            gameManager.EnemyShot(shot);
        }
    }