Ejemplo n.º 1
0
    public override void DoAction()
    {
        GetComponent <Fuel>().Amount -= ShootCost;

        GameObject g = new GameObject();

        g.name = "bullet";

        SpriteRenderer r = g.AddComponent <SpriteRenderer>();        //to show sprite

        r.sprite           = Resources.Load <Sprite>("Images/bullet");
        r.sortingLayerName = "Layer3";
        Vector3 size = r.sprite.bounds.size;

        g.transform.localScale = new Vector3(InGamePosition.tileW / size.x / 3f, InGamePosition.tileH / size.y / 3f);

        InGamePosition tmp = g.AddComponent <InGamePosition>();        //to update position

        tmp.x = GetComponent <InGamePosition>().x;
        tmp.y = GetComponent <InGamePosition>().y;

        Speeder speeder = g.AddComponent <Speeder>();        //to have speed

        speeder.v        = ShootSpeed;
        speeder.RideCost = 0.1f;

        //for speeder to work
        g.AddComponent <Fuel>().Amount = 10; //to have fuel for speeder

        g.AddComponent <Destroyer>();        //to destroy obstacles
        g.AddComponent <Flyier>();           //to not fall into holes
    }
Ejemplo n.º 2
0
    public void Prepare(CarConfig carConfig, Dictionary <int, GameObject> streets, Mission mission)
    {
        Streets = streets;

        SpriteRenderer carRenderer = gameObject.AddComponent <SpriteRenderer>();
        Texture2D      carT        = (Texture2D)carConfig.CarTexture;

        carRenderer.sprite           = Sprite.Create(carT, new Rect(0, 0, carT.width, carT.height), new Vector2(0.5f, 0.5f));
        carRenderer.sortingLayerName = "Layer3";

        float scale = InGamePosition.tileH / carRenderer.bounds.size.y;

        gameObject.transform.localScale = new Vector3(scale, scale);


        if (carConfig.CarStatistics[CarStatisticType.SHIELD].Value > 0)
        {
            ShieldCompo sc = gameObject.AddComponent <ShieldCompo>();
            sc.Prepare(carConfig.CarStatistics[CarStatisticType.SHIELD]);
        }

        Speeder speeder = gameObject.AddComponent <Speeder>();

        speeder.Prepare(carConfig.CarStatistics[CarStatisticType.COMBUSTION], mission.Env.CarStartingSpeed);

        Fuel fuel = gameObject.AddComponent <Fuel>();

        fuel.Prepare(carConfig.CarStatistics [CarStatisticType.FUEL_TANK], carConfig.CarStatistics [CarStatisticType.STARTING_OIL]);

        gameObject.AddComponent <InGamePosition>();

        float shooterProbability = 0;
        float jumperProbability  = 0;
        float ticket             = Random.Range(0, shooterProbability + jumperProbability);

        if (ticket <= jumperProbability)
        {
            Jumper jumper = gameObject.AddComponent <Jumper>();
            jumper.JumpDistance = 2;
            jumper.JumpCost     = 4;
        }
        else if (ticket <= jumperProbability + shooterProbability)
        {
            gameObject.AddComponent <Shooter>();
        }

        CarTurner carTurner = gameObject.AddComponent <CarTurner>();

        carTurner.Prepare(carConfig.CarStatistics [CarStatisticType.WHEEL]);

        Accelerator accelerator = gameObject.AddComponent <Accelerator> ();

        accelerator.Prepare(mission.Env.CarMaxSpeed, mission.Env.MaxSpeedDistance);

        gameObject.AddComponent <HurtTaker> ();
    }
    private bool TruckInPosition(Speeder truck)
    {
        if (!truck)
        {
            return(false);
        }
        float   closeEnough = 3.0f;
        Vector3 truckPos    = truck.transform.position;
        bool    xInPos      = truckPos.x > destination.x - closeEnough && truckPos.x < destination.x + closeEnough;
        bool    zInPos      = truckPos.z > destination.z - closeEnough && truckPos.z < destination.z + closeEnough;

        return(xInPos && zInPos);
    }
    // Use this for initialization
    void Start()
    {
        Red.SetActive(false);
        Blue.SetActive(false);
        Danger.SetActive(false);
        Warning.SetActive(false);
        ArrowL.SetActive(false);
        ArrowR.SetActive(false);
        Speeder.SetActive(false);

        red     = false;
        blue    = false;
        danger  = false;
        warning = false;
        arrowR  = false;
        arrowL  = false;
        speeder = false;

        slipR       = false;
        slipL       = false;
        nextTunnel  = false;
        tunnel      = false;
        way         = false;
        RoL         = false;
        RoR         = false;
        rotate      = 0;
        speed       = 2f;
        roteteSpeed = 10f;
        totateSpeed = 10f;
        check       = 0;
        checkTunnel = 0;
        checkRoY    = 0;
        timeCre     = 0;
        sp          = 10;
        maxSp       = 200;
        anim        = GetComponent <Animator>();
        source1     = GetComponent <AudioSource>();
        rb          = GetComponent <Rigidbody>();
    }
    public override bool PlayerMeetsConditions(Player player)
    {
        Speeder truck = player.GetComponentInChildren <Speeder>();

        return(player && !player.IsDead() && TruckInPosition(truck));
    }
    public void Detecter()
    {
        if (red == true)
        {
            Red.SetActive(true);
            //camShake.cameraShake();
            StartCoroutine(close());
        }

        if (blue == true)
        {
            Blue.SetActive(true);
            //camShake.cameraShake();
            StartCoroutine(close());
        }

        if (danger == true)
        {
            Danger.SetActive(true);
            StartCoroutine(close());
        }

        if (warning == true)
        {
            Warning.SetActive(true);
            StartCoroutine(close());
        }

        if (arrowL == true)
        {
            ArrowL.SetActive(true);
            StartCoroutine(close());
        }

        if (arrowR == true)
        {
            ArrowR.SetActive(true);
            StartCoroutine(close());
        }

        if (speeder == true)
        {
            Speeder.SetActive(true);
            StartCoroutine(close());
        }



        if (red == false)
        {
            Red.SetActive(false);
        }

        if (blue == false)
        {
            Blue.SetActive(false);
        }

        if (danger == false)
        {
            Danger.SetActive(false);
        }

        if (warning == false)
        {
            Warning.SetActive(false);
        }

        if (arrowL == false)
        {
            ArrowL.SetActive(false);
        }

        if (arrowR == false)
        {
            ArrowR.SetActive(false);
        }
        if (speeder == false)
        {
            Speeder.SetActive(false);
        }
    }