- Home /
AddForce to Camera
Hello everybody! I am making a game where my player is looking through a camera. (Like fps, but more fp of fps.) My script is:
using UnityEngine;
using System.Collections;
public class jumpAfterTest : MonoBehaviour
{
public void JAT ()
{
Debug.Log("Me is JAT");
//add effect here
GetComponent<Rigidbody>().AddForce (transform.up * 1000);
}
}
It is unusual, I know, because it is triggered by:
using UnityEngine;
using System.Collections;
public class Test: MonoBehaviour
{
public jumpAfterTest _jumpAfterTest;
void OnMouseDown()
{
Debug.Log ("Mouse Down");
_jumpAfterTest.JAT ();
}
void OnMouseUp()
{
Debug.Log ("Mouse up");
}
}
As far as I can see, my addforce code is fine, but the jumpAfterTest script won't work. My camera that the script is attached to doesn't move. I don't know why it won't. jumpAfterTest is receiving input. Please help me out if you can. Is this AddForce not working because it is a camera it is attached to? Thanks. ( By the way, I am in ios)
Answer by Requiem36 · Aug 04, 2015 at 01:34 PM
Make sure your Camera have a Rigidbody component on it, make sure your input is called, make sure the force you apply on it is enough, make sure your Camera's position is not overriden by anything.
Also Camera must have a Collider (for gravity) and The Object you click on must have a Collider too or it must be a GUIElement. Btw the script works fine.