void OnTargetCollision(DetectMarker target)
 {
     // incorporate target collisions between frames? ASAP?
 }
示例#2
0
    // // Option to load saved target config
    // private void LoadTargetConfig(string path) {
    //     // load target config file from path on disk
    // }
    // public string DebugConfigPath = "";
    // [ContextMenu("Load Target Configuration")]
    // private void DebugConfigLoad() {
    //     LoadTargetConfig(DebugConfigPath);
    // }


    // Awake() is called when an object is instantiated and activated for the first time, so it will happen on a scene loading transition.
    // This is different to Start() which only happens if this script is active on application start, and only happens once.
    void Awake()
    {
        // Set floot color to customized choice
        Floor.material.color = FloorColor;

        // Scale the object we will be spawning such that it's height matches the height of our box
        Vector3 prefabScale = TargetPrefab.transform.localScale;

        TargetPrefab.transform.localScale = new Vector3(TargetWidth, transform.localScale.y * .5f, TargetWidth);
        int obsCount = NumObstaclesToSpawn;

        for (int i = 0; i < NumTargetsToSpawn; i++)
        {
            bool crowded = false;
            // Pick a random location within our box
            Vector3 randomPositionWithin = new Vector3(Random.Range(-1f, 1f), 1, Random.Range(-1f, 1f));
            randomPositionWithin = transform.TransformPoint(randomPositionWithin * 0.5f);
            Transform[] allChildren = GetComponentsInChildren <Transform>();
            foreach (Transform child in allChildren)
            {
                if (Vector3.Distance(child.position, randomPositionWithin) > MinDistBetweenObjects) // MinDist needs to be .25
                {
                    continue;
                }
                else
                {
                    crowded = true;
                    break;
                }
            }

            if (crowded == true)
            {
                i--;
                continue;
            }

            // Create our target
            GameObject   targetInstance = Instantiate(TargetPrefab, randomPositionWithin, Quaternion.identity);
            DetectMarker targetScript   = targetInstance.GetComponent <DetectMarker>();

            // Set color, sound, and targeted markers
            //int randomIndex = Random.Range(0, Colors.Count);
            bool isObstacle = (Random.value < .5 ? true : false);
            if (isObstacle)
            {
                if (obsCount <= 0)
                {
                    isObstacle = false;
                }
                obsCount--;
            }
            // targetScript.SetColor((isObstacle ? ObstacleColor : TargetColor));
            targetScript.SetMaterial((isObstacle ? ObstacleMat : TargetMat));
            // targetScript.GetComponentInChildren<DetectMarker>().SetColor((isObstacle ? ObstacleColor : TargetColor));
            targetScript.SetAudioFeedback((isObstacle ? Sounds[2] : Sounds[0]));
            targetScript.targetJoints = HitJoints;

            // Organize underneath self in hierarchy
            targetInstance.transform.SetParent(transform);
        }
    }