- Home /
how to make my camera follow multiple children of objects?
I'm Try to make it too where you can buy different players and every scene needs to have the every character so that whatever you picked in the main menu it transfers the info to the next scene. the problem I'm having is that in every scene there's only one character (no others) and only one camera to follow it, i need to find a way where the camera can follow 1 character but the character is a child of a object with like 10 other objects(but the nine others are deactivated). if there is anyone that can help me or has any ideas that would help please don't hesitate to comment down below. (at this point I'm really up for anything) ..........................................................................................................................................................
CODE: Character Select
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CharacterSelect : MonoBehaviour {
private GameObject[] characterList;
private int index;
public static int Currency;
void Start ()
{
Currency = PlayerPrefs.GetInt("SCORE");
index = PlayerPrefs.GetInt("CharacterSelected");
characterList = new GameObject[transform.childCount];
// Fill the array with our Models
for (int i = 0; i < transform.childCount; i++)
characterList[i] = transform.GetChild(i).gameObject;
// We toggle off their renderer
foreach (GameObject go in characterList)
go.SetActive(false);
// We toggle on the selected Character
if (characterList[index])
characterList[index].SetActive(true);
}
public void ToggleLeft () {
characterList[index].SetActive(false);
index--;
if (index < 0)
index = characterList.Length - 1;
characterList[index].SetActive(true);
}
public void ToggleRight()
{
characterList[index].SetActive(false);
index++;
if (index == characterList.Length)
index = 0;
characterList[index].SetActive(true);
}
public void ApplyButton()
{
PlayerPrefs.SetInt("CharacterSelected", index);
}
}
CODE: Camera following One Player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowPlayer : MonoBehaviour {
public Transform player;
public float SmoothSpeed = 0.1f;
public float MaxDist;
public Vector3 Offset = new Vector3(0,8,-8);
void LateUpdate()
{
if (transform.position.z <= MaxDist)
{
Vector3 DesiredPosition = player.position + Offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, DesiredPosition, SmoothSpeed);
transform.position = smoothedPosition;
}
}
}
Here Are some Pictures:
Your answer
![](https://koobas.hobune.stream/wayback/20220612154400im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple player objects with using one camera 1 Answer
Camera Following Multiple Objects 0 Answers
Super Monkey Ball type Camera? 2 Answers
How to make your character move? 7 Answers
Follow an object with camera -1 Answers