public void TakeHurt(Tile fromWhat)
    {
        ShieldCompo sc = GetComponent <ShieldCompo> ();

        if (sc == null || !sc.TakeThis(fromWhat))
        {
            Die(fromWhat);
        }
    }
示例#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> ();
    }