Example #1
0
    // Use this for initialization
    void Start()
    {
        float width   = (columns - 1) * xSpacing;
        float height  = (rows - 1) * ySpacing;
        float depth   = (layers - 1) * zSpacing;
        float xOffset = width / 2;
        float yOffset = height / 2;
        float zOffset = depth / 2;

        for (int x = 0; x < columns; x++)
        {
            for (int y = 0; y < rows; y++)
            {
                for (int z = 0; z < layers; z++)
                {
                    Vector3 pos = new Vector3(targetPlacement.position.x - xOffset + (x * xSpacing), targetPlacement.position.y - zOffset + (z * zSpacing),
                                              targetPlacement.position.z - yOffset + (y * ySpacing));
                    GameObject target     = (GameObject)GameObject.Instantiate(targetPrefab, pos, targetPlacement.rotation);
                    int        colorIndex = randomMaterials[Random.Range(0, randomMaterials.Length)];
                    //target.renderer.material = materials[colorIndex];
                    TargetColor tc = target.GetComponentInChildren <TargetColor>();
                    tc.setColorIndex(colorIndex);
                    tc.setMaterial(materials[colorIndex]);
                }
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        delay -= Time.deltaTime;

        if ((delay <= 0.0f) && (currentRing == null))
        {
            currentRing = (GameObject)GameObject.Instantiate(ringPrefab, ringPlacement.position, ringRotation);
            TargetColor tc = currentRing.GetComponentInChildren <TargetColor>();

            int colorIndex = randomMaterials[Random.Range(0, randomMaterials.Length)];
            //currentRing.renderer.material = materials[colorIndex];

            tc.setColorIndex(colorIndex);
            tc.setMaterial(materials[colorIndex]);

            delay = 0f;
        }

        if (currentRing != null)
        {
            if (Input.GetMouseButton(0))
            {
                // Add force up to max
                throwForceTime += Time.deltaTime;
                throwForce      = Mathf.Lerp(minThrowForce, maxThrowForce, throwForceTime);

                powerMeter.setLevel(Mathf.FloorToInt(throwForce / 200));
            }

            if (Input.GetMouseButtonUp(0))
            {
                // Throw ring
                Rigidbody rb = currentRing.GetComponent <Rigidbody>();
                rb.isKinematic = false;
                rb.AddForce(mouselookObject.transform.forward * throwForce);

                currentRing    = null;
                delay          = delayAmount;
                throwForceTime = 0f;

                powerMeter.setLevel(0);
            }
        }

        if (Input.GetMouseButton(1))
        {
            //ringRotation = ringRotation * Quaternion.AngleAxis(Input.GetAxis("Mouse X") * mouseMultiplier, Vector3.up);
            ringRotation = ringRotation * Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * mouseMultiplier, Vector3.right);
            if (currentRing != null)
            {
                currentRing.transform.rotation = mouselookObject.transform.rotation * ringRotation;
            }
        }
        else
        {
            mouselookX = Mathf.Clamp(mouselookX - (Input.GetAxis("Mouse Y") * mouseMultiplier), minMouselookX, maxMouselookX);
            mouselookY = Mathf.Clamp(mouselookY + (Input.GetAxis("Mouse X") * mouseMultiplier), minMouselookY, maxMouselookY);

            mouselookObject.transform.localEulerAngles = new Vector3(mouselookX, mouselookY, 0f);

            if (currentRing != null)
            {
                currentRing.transform.position = ringPlacement.position;
                currentRing.transform.rotation = mouselookObject.transform.rotation * ringRotation;
            }
        }
    }