In the Hierarchy i have a FPSController and as child of it FirstPersonCharacter. I can get script that attached to the FPSController but not from the FirstPersonCharacter.
What i want to get is the Blur script from the FirstPersonCharacter.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class FadeScript : MonoBehaviour
{
public CharacterController firstPersonCharacter;
public FirstPersonController fpc;
public float fadeDuration = 5;
public float speed;
private Material material;
private float targetAlpha = 0;
private float lerpParam;
private float startAlpha = 1;
private bool rotated = false;
void Start()
{
material = GetComponent<Renderer>().material;
SetMaterialAlpha(1);
fpc.enabled = false;
}
void Update()
{
lerpParam += Time.deltaTime;
float alpha = Mathf.Lerp(startAlpha, targetAlpha, lerpParam / fadeDuration);
SetMaterialAlpha(alpha);
if (alpha == 0)
{
fpc.enabled = true;
if (rotated == false)
{
fpc.GetComponent<FirstPersonController>().enabled = false;
fpc.transform.localRotation = Quaternion.Slerp(fpc.transform.rotation, Quaternion.Euler(0, 0, 0), speed * Time.deltaTime);
}
if (fpc.transform.localRotation == Quaternion.Euler(0,0,0))
{
fpc.GetComponent<FirstPersonController>().enabled = true;
firstPersonCharacter.GetComponent<Blur>
rotated = true;
}
}
}
public void FadeTo(float alpha, float duration)
{
startAlpha = material.color.a;
targetAlpha = alpha;
fadeDuration = duration;
lerpParam = 0;
}
private void SetMaterialAlpha(float alpha)
{
Color color = material.color;
color.a = alpha;
material.color = color;
}
}
I can get scripts from the FPSController like this:
fpc.GetComponent<FirstPersonController>().enabled = true;
But i can't get the Blur script from the firstPersonCharacter. I tried before instead:
public CharacterController firstPersonCharacter;
With GameObject:
public GameObject firstPersonCharacter;
But Blur is not exist. When i make GetComponent The Blur is not exist.