- Home /
Question by
sayuki801 · Jul 23, 2015 at 10:08 PM ·
c#cameracamera-movement
How to move a camera combination of x and y axis
using UnityEngine; using System.Collections;
public class CameraShake : MonoBehaviour {
public ShakeTrigger shaketrigger;
private float startingShakeDistance = 8;
private float decreasePercentage = 5;
private float shakeSpeed = 50;
private int numberOfShakes = 10;
private Camera cam;
public IEnumerator CameraShakes () {
float hitTime = Time.time;
float originalPosition = cam.transform.localPosition.x;
int shake = 0;
float shakeDistance = startingShakeDistance;
for(shake = numberOfShakes; shake >= numberOfShakes; shake--)
{
float timer = (Time.time - hitTime)*shakeSpeed;
cam.transform.localPosition.x = originalPosition + Mathf.Sin(timer) * shakeDistance;
if(timer > Mathf.PI*2)
{
hitTime = Time.time;
shakeDistance *= decreasePercentage;
shake --;
}
yield return null;
}
cam.transform.localPosition.x = originalPosition;
}
}
using UnityEngine; using System.Collections;
public class ShakeTrigger : MonoBehaviour {
public CameraShake m_camerashake;
void Start () {
m_camerashake = GameObject.Find("CameraFPS").GetComponents(CameraShake);
}
void OnTriggerEnter(Collider Col)
{
if(Col.tag == "Player")
{
StartCoroutine(m_camerashake.CameraShakes());
}
}
}
Assets/Scripts/EQ/CameraShake.cs(33,31): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.localPosition'. Consider storing the value in a temporary variable
please help me dont know how to resovle this problem i want to shake my camera like there is an Eq but it says i cant store localPosition x to a original positon
Comment
Your answer
Follow this Question
Related Questions
Camera Follow works partially, need help to finish the script 3 Answers
How do I program camera movement 2 Answers
My camera won't move properly. 1 Answer
Multiple Cars not working 1 Answer