예제 #1
0
    void Start()
    {
        AfficheScore       = GetComponentInChildren <TextMesh>();
        AfficheScore.color = Couleur;
        Gestion            = FindObjectOfType <GestionnaireDeJeu>();
        OriginalScale      = transform.lossyScale.magnitude;
        cam          = GameObject.Find("CameraJeu").GetComponent <Camera>();
        rigid        = GetComponent <Rigidbody>();
        distToGround = GetComponent <Collider>().bounds.extents.y + (.25f * transform.localScale.y);
        timerTir     = 1;



        if (MesControles is ProfilTactile)
        {
            MesControles   = gameObject.AddComponent <ProfilTactile>();
            Cursor.visible = false;
        }

        DebugAndroid.LogSpecific("Player_" + NumPlayer + " spawn", MesControles.ToString());

        Line       = GetComponentInChildren <LineRenderer>();
        Invincible = true;
        Invoke("RemoveInvincibilite", 2);
        Invoke("ClignoteInvincible", .05f);
        Model3D.material.color = Couleur;
        Invoke("KillInactif", 5);
    }
예제 #2
0
    // Start is called before the first frame update
    void Start()
    {
        Gestion       = FindObjectOfType <GestionnaireDeJeu>();
        OriginalScale = transform.lossyScale.magnitude;
        cam           = GameObject.Find("CameraJeu").GetComponent <Camera>();
        rigid         = GetComponent <Rigidbody>();
        distToGround  = GetComponent <Collider>().bounds.extents.y + (.25f * transform.localScale.y);
        timerTir      = 1;

        /*MesControles = ProfilControle.GetMyProfil(this);
         * if (MesControles is ProfilTactile)
         * {
         *  MesControles = gameObject.AddComponent<ProfilTactile>();
         *  Cursor.visible = false;
         * }*/

        MesControles = gameObject.AddComponent <BotController>();

        DebugAndroid.LogSpecific("Player_" + NumPlayer + " spawn", MesControles.ToString());

        Line       = GetComponentInChildren <LineRenderer>();
        Invincible = true;
        Invoke("RemoveInvincibilite", 1);
        InvokeRepeating("ClignoteInvincible", 0, .1f);

        Model3D.material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
        Model3D.material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
        Model3D.material.SetInt("_ZWrite", 0);
        Model3D.material.DisableKeyword("_ALPHATEST_ON");
        Model3D.material.DisableKeyword("_ALPHABLEND_ON");
        Model3D.material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
        Model3D.material.renderQueue = 3000;

        foreach (Transform tr in GetComponentsInChildren <Transform>())
        {
            tr.gameObject.layer = 11;
        }

        Color transparent = Couleur;

        transparent.a = .5f;

        Model3D.material.color = transparent;

        ParticleSystem SpawnParticle = FindObjectOfType <ParticleSystem>();

        SpawnParticle.startColor = Couleur;
        SpawnParticle.Play();

        /* Gradient grad = new Gradient();
         * grad.colorKeys = new GradientColorKey[2] { new GradientColorKey(Color.red, 0), new GradientColorKey(Color.red, 1) };
         * grad.alphaKeys = new GradientAlphaKey[3] { new GradientAlphaKey(.75f,0),new GradientAlphaKey(.75f,.5f), new GradientAlphaKey(0, 1) }; ;
         * Line.colorGradient = grad;*/
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        SyncMove = true;
        #region Déplacement

        if (MesControles.GetX() != 0)
        {
            DebugAndroid.LogSpecific("Player_" + NumPlayer + " move", "is moving, speed : " + MesControles.GetX());
            float acceleration = 5;
            if (MesControles.GetX() > 0 == rigid.velocity.x > 0)
            {
                acceleration = (Mathf.Abs(MesControles.GetX() * 5) - Mathf.Abs(rigid.velocity.x));
                if (acceleration < 0)
                {
                    acceleration = 0;
                }
            }

            acceleration = MesControles.GetX() * acceleration;

            /*if (MesControles.GetX() > 0)
             * {
             *  if (rigid.velocity.x > 5)
             *      acceleration = 0;
             *  else
             *      acceleration = 5 - rigid.velocity.x;
             * }
             * else
             * {
             *  if (rigid.velocity.x < -5)
             *      acceleration = 0;
             *  else
             *      acceleration = -5 - rigid.velocity.x;
             * }*/
            if (isGrounded())
            {
                rigid.velocity += Vector3.right * acceleration * Time.deltaTime * 5;
            }
            else
            {
                rigid.velocity += Vector3.right * acceleration * Time.deltaTime * 3;
            }
        }
        else
        {
            DebugAndroid.LogSpecific("Player_" + NumPlayer + " move", "is stopped");
            if (isGrounded())
            {
                rigid.velocity -= Vector3.right * rigid.velocity.x * 10 * Time.deltaTime;
            }
        }


        #endregion
        //////////
        #region Saut

        if (MesControles.GetJump() && isGrounded() && canJump)
        {
            rigid.velocity += Vector3.up * 7.5f;
            canJump         = false;
            Invoke("ResetCanJump", .2f);
        }

        #endregion
        //////////
        #region Orientation Bazooka

        if (MesControles.NomProfil == "Clavier/Souris")
        {
            Vector3 point = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -cam.transform.localPosition.z));
            DirectionTir = point - transform.position;
        }
        else if (MesControles is ProfilTactile)
        {
            ProfilTactile MyCont   = (ProfilTactile)MesControles;
            Vector2       position = MyCont.ShotPosition;
            Vector3       point    = cam.ScreenToWorldPoint(new Vector3(position.x, position.y, -cam.transform.localPosition.z));
            DirectionTir = point - transform.position;
        }
        else
        {
            DirectionTir += (MesControles.GetX2() * Vector3.right + MesControles.GetY2() * Vector3.up) * 2000 * Time.deltaTime;
        }
        DirectionTir.Normalize();
        //Bazooka.localEulerAngles = Vector3.right * Mathf.Atan2(DirectionTir.x, DirectionTir.y) * Mathf.Rad2Deg;

        //Animation
        if (isGrounded())
        {
            float speed = DirectionTir.x * rigid.velocity.x;
            anim.SetBool("Flying", false);
            if (Mathf.Abs(speed) < .1f)
            {
                anim.SetBool("Stop", true);
                anim.speed = 1;
            }
            else
            {
                anim.SetBool("Stop", false);
                anim.SetBool("MarcheDroite", speed > 0);
                anim.speed = Mathf.Abs(rigid.velocity.x);
            }
        }
        else
        {
            anim.SetBool("Flying", true);
            anim.speed = 1;
        }



        Line.SetPosition(1, new Vector3(0, DirectionTir.y, DirectionTir.x));
        Line.SetPosition(2, new Vector3(0, DirectionTir.y * 1.15f, DirectionTir.x * 1.15f));
        body.localEulerAngles = new Vector3(0, -90 * DirectionTir.x + 90, 0);

        Spine1.localEulerAngles = Spine2.localEulerAngles = new Vector3(-25 * DirectionTir.y + 15, 0, 0);

        #endregion
        //////////
        #region Tir
        timerTir += Time.deltaTime;

        if (MesControles.GetShoot() && timerTir >= 1)
        {
            timerTir = 0;
            GameObject instance = Instantiate(Rocket, new Vector3(Bazooka.position.x, Bazooka.position.y, transform.position.z), Quaternion.Euler(DirectionTir));
            instance.GetComponent <Rocket>().SetSpeed(DirectionTir, 15f, this);
        }
        #endregion
    }