Inheritance: MonoBehaviour
コード例 #1
0
ファイル: BroomPainter.cs プロジェクト: razuk-78/Examples
    void FixedUpdate()
    {
        Ray        ray = new Ray(RaycastOrigin.position, RaycastOrigin.forward);
        RaycastHit hit;

        Debug.DrawRay(RaycastOrigin.position, RaycastOrigin.forward * SprayRange, Color.blue);
        if (Physics.Raycast(ray, out hit, SprayRange, ImpactMask))
        {
            WaterScript water = hit.collider.gameObject.GetComponent <WaterScript>();
            if (water)
            {
                water.Rewater();
            }
            else
            {
                GameObject spray = Instantiate(SprayImpact, hit.point, Quaternion.LookRotation(Vector3.forward, hit.normal));
            }
            //PlayAudio2();
            PlayAudioIfBroomMove();
        }
        else
        {
            audio.Stop();
        }
    }
コード例 #2
0
 public void OnTriggerExit2D(Collider2D col)
 {
     if (!cambiandoDeCharco)
     {
         charcoActual = null;
     }
     cambiandoDeCharco = false;
 }
コード例 #3
0
 public void OnTriggerEnter2D(Collider2D col)
 {
     if (charcoActual != null)
     {
         cambiandoDeCharco = true;
     }
     if (col.transform.gameObject.layer == 4)
     {
         charcoActual = col.gameObject.GetComponent <WaterScript> ();
     }
 }
コード例 #4
0
    Color32[] ApplyColors(Vector3[] vertices)
    {
        // set color bands as percentages of total height
        Color32[] colors    = new Color32[vertices.Length];
        float[]   maxAndMin = getMaxAndMin(vertices);
        float     max       = maxAndMin[0];
        float     min       = maxAndMin[1];
        float     diff      = max - min;

        float snowHeight  = diff * snowPerc + min;
        float rockHeight  = diff * rockPerc + min;
        float grassHeight = diff * grassPerc + min;
        float sandHeight  = diff * sandPerc + min;
        float waterHeight = grassHeight - ((grassHeight - sandHeight) * 0.6f);

        for (int i = 0; i < vertices.Length; i++)
        {
            if (vertices[i].y <= sandHeight)
            {
                // brown
                colors[i] = new Color32(92, 67, 53, 255);
            }
            else if (vertices[i].y <= grassHeight)
            {
                // sandy
                colors[i] = new Color32(232, 196, 128, 255);
            }
            else if (vertices[i].y <= rockHeight)
            {
                // green grass
                colors[i] = new Color32(37, 136, 42, 255);
            }
            else if (vertices[i].y <= snowHeight)
            {
                // rock grey
                colors[i] = new Color32(153, 153, 152, 255);
            }
            else
            {
                // snow white
                colors[i] = new Color32(255, 255, 255, 255);
            }
        }
        ;

        // update the water now
        referenceObject = GameObject.Find("Water");
        referenceScript = referenceObject.GetComponent <WaterScript>();
        referenceScript.setWaterHeight(sideSize, waterHeight);

        return(colors);
    }
コード例 #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 extend = boxCollider.size * 0.7f;

        Collider[] waters = Physics.OverlapBox(boxCollider.transform.TransformPoint(boxCollider.center), extend,
                                               boxCollider.transform.rotation, WaterLayer);

        foreach (var v in waters)
        {
            WaterScript water = v.GetComponent <Collider>().gameObject.GetComponent <WaterScript>();
            water.CleanUp(Time.deltaTime);
        }
    }
コード例 #6
0
    // Use this for initialization
    void Start()
    {
        bombs     = GameObject.Find("bomb pool").GetComponent <ObjectPool>();
        clouds    = GameObject.Find("cloud pool").GetComponent <ObjectPool>();
        stars     = GameObject.Find("star pool").GetComponent <ObjectPool>();
        rafts     = GameObject.Find("raft pool").GetComponent <ObjectPool>();
        water     = GameObject.Find("water").GetComponent <WaterScript>();
        music     = GameObject.Find("MusicController").GetComponent <MusicController>();
        nextTick  = Time.time + tickDuration;
        soundMode = Log.CurrentMode;
        Log.StartLevel(Time.time);

        StartCoroutine(LevelScript());
    }
コード例 #7
0
    // Use this for initialization
    void Start()
    {
        boxCollider       = GetComponent <BoxCollider2D> ();
        rb2D              = GetComponent <Rigidbody2D> ();
        inverseMoveTime   = 1.0f / moveTime;
        animator          = GetComponent <Animator> ();
        GuardStepSource   = GetComponent <AudioSource> ();
        dead              = false;
        charcoActual      = null;
        cambiandoDeCharco = false;
        side_size         = GetComponent <SpriteRenderer> ().bounds.size.x;
        float collider_size = (float)(side_size - 0.1);

        GetComponent <BoxCollider2D> ().size.Set(collider_size, collider_size);
        //List<Node> path = FindPath (new Vector2((int)transform.position.x, (int)transform.position.y), new Vector2 (5, 4));
        //foreach (Node n in path)
        //	print (n.pos);
    }
コード例 #8
0
    private void FireBullet()
    {
        audio.Play();
        particles.Emit(50);

        Debug.Log("Spray!");
        Ray        ray = new Ray(RaycastOrigin.position, RaycastOrigin.forward);
        RaycastHit hit;

        Debug.DrawRay(RaycastOrigin.position, RaycastOrigin.forward * SprayRange, Color.blue);
        if (Physics.Raycast(ray, out hit, SprayRange, ImpactMask))
        {
            WaterScript water = hit.collider.gameObject.GetComponent <WaterScript>();
            if (water)
            {
                water.Rewater();
            }
            else
            {
                GameObject spray = Instantiate(SprayImpact, hit.point, Quaternion.LookRotation(Vector3.forward, hit.normal));
            }
        }
    }
コード例 #9
0
ファイル: WaterHitScript.cs プロジェクト: joramwessels/SMT
 void Start()
 {
     water = transform.parent.gameObject.GetComponent <WaterScript>();
 }
コード例 #10
0
    private void Shoot()
    {
        // shoot projectiles
        switch (_weaponMode)
        {
        case WeaponMode.WATER:
            GameObject newWaterball = Instantiate(WaterBall, ShootingPoint.position, Quaternion.FromToRotation(Vector3.forward, Vector3.forward));
            newWaterball.GetComponent <Rigidbody>().AddForce(ShootingPoint.transform.forward * 1000f);
            break;

        case WeaponMode.ICE:
            RaycastHit hitz;
            Ray        ray          = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            Vector3    IceDirection = Vector3.zero;
            if (Physics.Raycast(ray, out hitz))
            {
                Debug.Log(hitz.transform.name);
                IceDirection = hitz.point - ShootingPoint.position;
            }
            else
            {
                IceDirection = ray.GetPoint(100f) - ShootingPoint.position;
            }
            GameObject newIceCone = Instantiate(IceCone, ShootingPoint.position, Quaternion.FromToRotation(Vector3.up, IceDirection));
            newIceCone.GetComponent <Rigidbody>().AddForce(IceDirection.normalized * 1000f);
            break;

        case WeaponMode.FIRE:
            GameObject newFireball = Instantiate(FireBall, ShootingPoint.position, Quaternion.FromToRotation(Vector3.forward, Vector3.forward));
            newFireball.GetComponent <Rigidbody>().AddForce(ShootingPoint.transform.forward * 1000f);
            break;

        case WeaponMode.LIGHTNING:
            RaycastHit hit;
            Ray        LightningRay = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            if (Physics.Raycast(LightningRay, out hit, 100f))
            {
                Vector3 direction = (hit.point - ShootingPoint.position);
                int     distance  = 2;
                for (int i = 0; i < direction.magnitude; i += distance)
                {
                    GameObject newLightning = Instantiate(Lightning, ShootingPoint.position + direction.normalized * i, Quaternion.FromToRotation(Vector3.up, direction));
                    Destroy(newLightning, 0.5f);
                }

                if (hit.transform.tag == "water")
                {
                    WaterScript wScript = hit.transform.GetComponent <WaterScript>();
                    if (wScript != null)
                    {
                        wScript.Electrocute();
                    }
                }
            }
            break;

        case WeaponMode.AIR:
            GameObject newAirball = Instantiate(AirBall, ShootingPoint.position, Quaternion.FromToRotation(Vector3.forward, Vector3.forward));
            newAirball.GetComponent <Rigidbody>().AddForce(ShootingPoint.transform.forward * 1000f);
            break;

        case WeaponMode.SUCTION:
            RaycastHit suctionHit;
            Ray        suctionRay = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            if (Physics.Raycast(suctionRay, out suctionHit, 50f))
            {
                Vector3 retractionDirection = (transform.position - suctionHit.point);
                retractionDirection.y = 0;     // remove upwards/downwards force
                if (suctionHit.transform.tag == "Cube")
                {
                    suctionHit.rigidbody.AddForce(retractionDirection.normalized * _suctionPower);
                }
            }
            break;
        }
    }