Hello. I am trying to build a shake screen script using one I found online. I keep getting the error “The type arguments for method `UnityEngine.Component.GetComponent()’ cannot be inferred from the usage. Try specifying the type arguments explicitly” If anyone could see where that would be coming from I would greatly appreciate it! I have marked the line that gives the error. Thanks in advance!
using UnityEngine;
using System.Collections;
public class ScreenShake : MonoBehaviour {
//editor exposed variables
public float ShakeAmount = 0.25f;
public float DecreaseFactor = 1.0f;
//class internal variables
private new Camera camera;
private Vector3 cameraPos;
private float shake = 0.0f;
void Awake(){
//go and find the camera
this.camera = (Camera)this.GetComponent(); ............error line..............
if (this.camera == null) {
//print an error
Debug.Log ("CameraShake:Unable to find 'camera' component attached to GameObject");
}
}
// Update is called once per frame
void Update () {
//public void Shake(float amount){}
if (this.shake > 0.0f) {
//clamp the shake amount back to zero and reset the camera position to our chached value
this.shake = 0.0f;
this.camera.transform.localPosition = this.cameraPos;
}
}
public void Shake(float amount){
if(this.shake<=0.0f){
this.cameraPos = this.camera.transform.position;
}
this.shake = amount;
}
}