예제 #1
0
    // Sets the navigation path for this drone.
    void SetNavPath(GameObject path)
    {
        NavPositions = new List <Transform>();
        DroneNavigationPath navPoints = path.GetComponent <DroneNavigationPath>();

        NavPositions.AddRange(navPoints.NavigationPoints);
        hasOutPoint = navPoints.HasOutPoint;
    }
    /// <summary>
    /// Spawns a drone at the first position in the NavigationPath.
    /// </summary>
    /// <param name="navIndex">Index of NavigationPath, Color, and Speed to use for the underdrone.</param>
    public void SpawnDrone(int index)
    {
        // Create drone and set initial position, rotation, scale.
        DroneNavigationPath path  = NavigationPaths[index].gameObject.GetComponent <DroneNavigationPath>();
        GameObject          drone = (GameObject)Instantiate(DronePrefab);

        drone.transform.parent   = this.transform;
        drone.transform.position = path.NavigationPoints[0].position;
        drone.transform.LookAt(path.NavigationPoints[1].transform);
        drone.transform.localScale = new Vector3(0.72f, 0.72f, 0.72f);

        // Set drone's speed and navigation path.
        DroneBehavior behavior = drone.AddComponent <DroneBehavior>();

        behavior.NavPath      = NavigationPaths[index].gameObject;
        behavior.Speed        = DroneSpeeds[index];
        behavior.NavPathIndex = index;

        // Set drone's color.
        FriendlyDrone friendly = drone.GetComponentInChildren <Animator>().gameObject.AddComponent <FriendlyDrone>();

        friendly.EmissiveColor = DroneColors[index];
    }