Hey there!
I recently purchased this great product and i really really like it. I am still studying some of the tutorials and trying to apply some of the tutorials to my personal needs.
So i have a certain question respectively a problem. I searched this forum and didn't find a solution (maybe i am too dumb to search properly, so if there IS actually a solution: I am very sorry, would be really grateful if someone just could give a link to the topic!)
First of all, here are some details, so you guys can structure the Project:
Genre: a 2D Jump'n'Run Game for the iOS
Plugins:
Uni2D (2D Framework for the Leveldesign and some Spriteanimations),
SmoothMoves (2D BoneAnimations),
nGUI (for the work with GUI-Elements),
FarseerUnity (Physics), of course
PlayMaker and some other Plugins which doesn't matter right now to discuss my problem
So i built my level with Uni2D, arranging the Sprites like i want them to; then i gave the Sprite-Plattforms with FarseerUnity Physics like this:
The Playercharacter is a SmoothMoves-BoneAnimation-Gameobject which also has FarseerUnity-Physics in order to move around.
The GUI is very basic, a Life-Gauge, a Pause-Button, three MoveButtons (Left, Right, Jump) and an Attack-Button. As mentioned above, it is made with nGUI. The Movement-Buttons and the Pause-Button are all UIImage-Buttons.
So, the problem is:
I would like to move my character with the buttons via PlayMaker! I can't manage to do that.
I moved my character around with the keyboard with this script:
void Update ()
{
if(Input.GetKey(KeyCode.RightArrow))
{
float velocityScale = 2.5f;
velocity.Y = character.LinearVelocity.Y;
velocity.X = velocityScale * m_normal.X;
character.LinearVelocity = velocity;
}
else if(Input.GetKey(KeyCode.LeftArrow))
{
float velocityScale = 2.5f;
velocity.Y = character.LinearVelocity.Y;
velocity.X = velocityScale * -m_normal.X;
character.LinearVelocity = velocity;
}
else if(Input.GetKey(KeyCode.UpArrow))
{
float velocityScale = character.Mass * 0.5f;
character.ApplyLinearImpulse(new FVector2(0, velocityScale));
}
}
THEN i found here in the forum this link:
http://www.tasharen.com/?page_id=160and tried things out. I had to made three different Movement-Scripts which I attached to the UIImage-Button-Objects, and all had the OnClick()-Function, like for example the Jump-Script:
public GameObject characterObject;
// Farseer Bodies
private Body character;
//Farseer Vectors
private FVector2 velocity;
private FVector2 m_normal;
// Use this for initialization
void Start ()
{
character = characterObject.GetComponent<FSBodyComponent>().PhysicsBody;
character.FixedRotation = true;
velocity = character.LinearVelocity;
m_normal = new FVector2(1,0);
}
void OnClick()
{
float velocityScale = KnightShape.Mass * 5.5f;
character.ApplyLinearImpulse(new FVector2(0, velocityScale));
}
It did work, but i don't want to use it like that at all.
I would prefer an elegant solution with PlayMaker. Can someone help?