コード例 #1
0
    public void Restart()
    {
        GameObject newDrone = Instantiate(originalDrone.gameObject);

        newDrone.SetActive(true);
        newDrone.transform.SetParent(this.transform);
        newDrone.transform.position = this.transform.position;
        if (currentDrone != null)
        {
            currentDrone.Stop(newDrone);
            oldDrones.Add(currentDrone);
            int fadecount = 0;

            foreach (DroneController droneController in oldDrones)
            {
                droneController.SetDeadAlpha(Mathf.Clamp(1.0f - oldDrones.Count * 0.09f + fadecount * 0.10f, 0.0f, 1.0f));
                if (droneController != null)
                {
                    Physics2D.IgnoreCollision(newDrone.GetComponent <Collider2D>(), droneController.gameObject.GetComponent <Collider2D>());
                }
                fadecount += 1;
            }
            if (oldDrones.Count > 10)
            {
                Destroy(oldDrones[0].gameObject);
                oldDrones.RemoveAt(0);
            }
        }
        currentDrone = newDrone.GetComponent <DroneController>();
        currentDrone.GetComponent <Rigidbody2D>().velocity += initialVelocity;
        lostDrones += 1;
        AudioController.instance.JustBeep();
    }
コード例 #2
0
    // Update is called once per frame
    private void FixedUpdate()
    {
        if (team_tag == "Blue")
        {
            Debug.Log(shoot);
        }
        // Debug.Log("shoot :" + shoot);
        bool goodway = team_tag == "Blue" ? transform.position.x - ball.transform.position.x < 0 : transform.position.x - ball.transform.position.x > 0;

        if ((transform.position - ball.transform.position).magnitude < 13f && goodway && (transform.position - own_goal.transform.position).magnitude < 30f)
        {
            shoot = true;
        }
        else if (team_tag == "Blue" && ball.transform.position.x < 64)
        {
            shoot = true;
        }
        else if (team_tag == "Red" && ball.transform.position.x > 236)
        {
            shoot = true;
        }
        else
        {
            shoot = false;
        }

        if (shoot == true)
        {
            m_Drone.Move_vect((ball.transform.position - transform.position).normalized * m_Drone.max_acceleration);
        }
        else
        {
            Vector3 preferedPos     = OptimalPosition();
            float   currentVelocity = m_Drone.GetComponent <Rigidbody>().velocity.magnitude;
            if ((preferedPos - transform.position).magnitude > currentVelocity * 0.7)
            {
                Vector3 realVector = (preferedPos - transform.position).normalized * m_Drone.max_acceleration;
                m_Drone.Move_vect(realVector);
            }
            else
            {
                Vector3 realVector = (preferedPos - transform.position).normalized * currentVelocity / 5f;
                realVector.z = -realVector.z;
                // DebugPlus.DrawSphere(preferedPos, 5f);
                m_Drone.Move_vect(realVector);
            }
            if (team_tag == "Blue")
            {
                // DebugPlus.DrawSphere(preferedPos, 5f);
            }
        }
    }