コード例 #1
0
 void Awake()
 {
     if (!energyHolder)
     {
         energyHolder = GetComponentInParent <EnergyHolder>();
     }
     if (!shieldRechargerInteractable)
     {
         shieldRechargerInteractable = GetComponentInChildren <InteractableObject>();
     }
 }
コード例 #2
0
 void Awake()
 {
     if (!energyHolder)
     {
         energyHolder = GetComponent <EnergyHolder>();
     }
     if (!faction)
     {
         faction = GetComponentInParent <Faction>();
     }
 }
コード例 #3
0
 void Awake()
 {
     if (!energyHolder)
     {
         energyHolder = GetComponent <EnergyHolder>();
     }
     if (!energyBarSpriteRenterer)
     {
         energyBarSpriteRenterer = GetComponentInChildren <SpriteRenderer>();
     }
     if (!animator)
     {
         animator = GetComponentInChildren <Animator>();
     }
 }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        targetObj = targetObject.transform.position;
        //print((Input.GetAxis("Fire2")));
        if (ballCharge < .99)
        {
            text.text = (Mathf.RoundToInt(ballCharge * 100 + 1)).ToString() + "%";
        }
        else
        {
            text.text = "100%";
        }
        // print(energyLevel);
        if (player1)
        {
            if (Input.GetAxis("Fire2") > 0)
            {
                ChargeBolt();
                if (charging1 == false)
                {
                    chargeUp.Play();
                }
                charging1 = true;

                print(charging1);
                sl.value     = ballCharge;
                move.canMove = false;
                RaycastHit checkTile;

                if (Physics.Raycast(transform.position, -transform.up, out checkTile, 1, layer))
                {
                    GameObject tileBelow = checkTile.transform.gameObject;
                    tileBelow.GetComponent <Energy>().startDraining();
                    //tileBelow.GetComponent<Energy>().energy -= tileBelow.GetComponent<Energy>().energy / tileBelow.GetComponent<Energy>().maxEnergy;
                }
            }


            if (Input.GetAxis("Fire2") == 0)
            {
                if (charging1)
                {
                    chargeUp.Stop();

                    chargeRelease.Play();
                    boltFlying.Play();

                    sl.value     = 0;
                    move.canMove = true;
                    Vector3    CubeHeight  = new Vector3(0, -0.5f, 0);
                    GameObject thunderBolt =
                        Instantiate(projectile, transform.position + CubeHeight, Quaternion.identity);
                    //thunderBolt.transform.localScale += ChargeBolt();
                    Rigidbody boltRB = thunderBolt.AddComponent <Rigidbody>();

                    boltRB.velocity = BallisticVel(targetObj, shootAngle);
                    thunderBolt.transform.LookAt(BallisticVel(targetObj, shootAngle));
                    //boltEnergyscript.energyLevel() += energyLevel;
                    EnergyHolder EH = thunderBolt.AddComponent <EnergyHolder>();
                    EH.Target(targetObj, shootAngle);

                    RaycastHit checkTile;

                    if (Physics.Raycast(transform.position, -transform.up, out checkTile, 1, layer))
                    {
                        //Debug.Log(checkTile.transform.name);
                        GameObject tileBelow     = checkTile.transform.gameObject;
                        float      energyDrained = Mathf.Floor(tileBelow.GetComponent <Energy>().energy *ballCharge);

                        //tileBelow.GetComponent<Energy>().drainEnergy(ballCharge);
                        tileBelow.GetComponent <Energy>().stopDraining();
                        EH.EnergyLevel(energyDrainAmount);
                    }



                    sizeIncrement     = Vector3.zero;
                    ballCharge        = 0;
                    energyDrainAmount = 0;
                    charging1         = false;
                }
            }

            /*if (Input.GetMouseButtonDown(0))
             * {
             *  RaycastHit hitInfo = new RaycastHit();
             *  bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo, layer);
             *  if (hit)
             *  {
             *      if (hitInfo.transform.gameObject.tag == "Tile")
             *      {
             *          //Vector3 temp = hitInfo.transform.gameObject.transform.position;
             *         // targetObj = temp + new Vector3(0, 0f, 0);
             *      }
             *  }
             * }*/
        }

        if (player2)
        {
            // Debug.Log("X: " + Input.GetAxis("ControllerX"));
            // Debug.Log("Y: " + Input.GetAxis("ControllerY"));
            var deadzone = 0.1f;

            /*if (Input.GetAxis("ControllerX") >= deadzone)              //Change to controller x axis
             * {
             *  cursor.transform.position += Vector3.right * controllerSensitivity;
             *
             *
             * }
             *
             * if (Input.GetAxis("ControllerX") <= -deadzone)                //Change to controller x axis
             * {
             *  cursor.transform.position -= Vector3.right * controllerSensitivity;
             *
             *
             * }
             *
             * if (Input.GetAxis("ControllerY") <= -deadzone)                     //Change to controller y axis
             * {
             *  cursor.transform.position += Vector3.up * controllerSensitivity;
             *
             *
             * }
             *
             * if (Input.GetAxis("ControllerY") >= deadzone)                     //Change to controller y axis
             * {
             *  cursor.transform.position -= Vector3.up * controllerSensitivity;
             *
             *
             * }
             *
             *
             *
             * Ray ray2 = Camera.main.ScreenPointToRay(cursor.transform.position);
             * RaycastHit hit2;
             *
             * if (Physics.Raycast(ray2, out hit2, 10000))
             * {
             *
             *  if (hit2.transform.tag == "Player1Tile")
             *  {
             *
             *
             *  }
             * }*/
            if (Input.GetAxis("Fire1") > 0)
            {
                ChargeBolt();
                if (charging == false)
                {
                    chargeUp.Play();
                }
                charging     = true;
                sl.value     = ballCharge;
                move.canMove = false;


                RaycastHit checkTile;


                if (Physics.Raycast(transform.position, -transform.up, out checkTile, 1, layer))
                {
                    GameObject tileBelow = checkTile.transform.gameObject;
                    tileBelow.GetComponent <Energy>().startDraining();
                    //tileBelow.GetComponent<Energy>().energy -= tileBelow.GetComponent<Energy>().energy / tileBelow.GetComponent<Energy>().maxEnergy;
                }
            }


            if (Input.GetAxis("Fire1") == 0) //Change to controller right trigger
            {
                sl.value = 0;
                if (charging)
                {
                    chargeUp.Stop();

                    chargeRelease.Play();
                    boltFlying.Play();

                    Vector3 CubeHeight = new Vector3(0, -0.5f, 0);
                    //Vector3 temp = hit2.transform.gameObject.transform.position;
                    //targetObj = temp + new Vector3(0, 0f, 0);
                    move.canMove = true;
                    GameObject thunderBolt =
                        Instantiate(projectile, transform.position + CubeHeight, Quaternion.identity);
                    //thunderBolt.transform.localScale += ChargeBolt();
                    //thunderBolt.gameObject.layer = 4;
                    Rigidbody boltRB = thunderBolt.AddComponent <Rigidbody>();
                    boltRB.velocity = BallisticVel(targetObj, shootAngle);
                    thunderBolt.transform.LookAt(BallisticVel(targetObj, shootAngle));
                    //boltEnergyscript.energyLevel() += energyLevel;
                    EnergyHolder EH = thunderBolt.AddComponent <EnergyHolder>();

                    RaycastHit checkTile;

                    if (Physics.Raycast(transform.position, -transform.up, out checkTile, 1, layer))
                    {
                        //Debug.Log(checkTile.transform.name);
                        GameObject tileBelow     = checkTile.transform.gameObject;
                        float      energyDrained = Mathf.Floor(tileBelow.GetComponent <Energy>().energy *ballCharge);

                        //tileBelow.GetComponent<Energy>().drainEnergy(ballCharge);
                        tileBelow.GetComponent <Energy>().stopDraining();
                        EH.EnergyLevel(energyDrainAmount);
                    }

                    sizeIncrement     = Vector3.zero;
                    ballCharge        = 0;
                    energyDrainAmount = 0;
                    charging          = false;
                }
            }
        }

        RaycastHit checkTileCharge;

        if (Physics.Raycast(transform.position, -transform.up, out checkTileCharge, 1, layer))
        {
            GameObject tileBelow = checkTileCharge.transform.gameObject;
            if (tileBelow.GetComponent <Energy>().energy <= 1f)
            {
                canCharge = false;
            }
            else
            {
                canCharge = true;
            }
        }
    }