Question by
Wesley21spelde · Sep 12, 2017 at 04:49 PM ·
networkingtransformtriggerfindwhen
Transform.find Does not work
Transform.Find is Not working when my player collides with the trigger of the explosion Script? Here is the script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ShakeCamera : MonoBehaviour {
// Transform of the camera to shake. Grabs the gameObject's transform
// if null.
public Transform camTransform;
// How long the object should shake for.
public float shakeDuration = 0f;
// Amplitude of the shake. A larger value shakes the camera harder.
public float shakeAmount = 0.7f;
public float decreaseFactor = 1.0f;
public bool shaketrue = false;
Vector3 originalPos;
void Start()
{
}
public void ExplosionShake()
{
Update();
}
void OnEnable()
{
originalPos = camTransform.localPosition;
}
void OnTriggerStay(Collider collider)
{
if (collider.gameObject.tag == "Player")
{
camTransform = transform;
transform.Find("FirstPersonCharacterCam");
collider.gameObject.GetComponentInChildren<Camera>();
shaketrue = true;
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
}
}
void Update()
{
if (shaketrue)
{
if (shakeDuration > 0)
{
camTransform.localPosition = originalPos + Random.insideUnitSphere * shakeAmount;
shakeDuration -= Time.deltaTime * decreaseFactor;
}
else
{
shakeDuration = 1f;
camTransform.localPosition = originalPos;
shaketrue = false;
}
}
}
public void shakecamera()
{
shaketrue = true;
//BroadcastMessage("shakecamera");
}
}
Comment
Your answer
Follow this Question
Related Questions
Trigger on player controller prefab not working? 0 Answers
[UNET] Transform sycing problem,[UNET] TRANSFORMATION SYCING PROBLEMS 0 Answers
Unity 5 Unet Network Rigidbody Syncing - Client sinking through objects. 0 Answers
Getting null pointer unless I give condition if it is null 1 Answer
How can i make my object go back to its start position? 3 Answers