Sunday, 24 June 2012

25 June 2012

For this assignment I did the score script, so when the ingredients collide with the bun the 1 point will be given. This will then instantiate a stars effect. The collided ingredients will then be parented to the bun and the score script will be passed on to it as well. Hence, the collided ingredient will in turn be the base of the burger. 5 points will end the game.

if (target.tag == "food")
{GUIMenu.score += 1;

target.rigidbody.isKinematic = true;
target.rigidbody.freezeRotation = true;
target.rigidbody.useGravity = false;
target.transform.parent = this.gameObject.transform;
target.gameObject.tag = "bottom";
GameObject addpointfxs = Instantiate(addpointfx, this.transform.position,Quaternion.identity) as GameObject;
addpointfxs.transform.parent = transform;
float ty =(.001f* Mathf.Pow(GUIMenu.score,2));
target.transform.localPosition = new Vector3(target.transform.localPosition.x, ty ,target.transform.localPosition.z);
target.rigidbody.collider.isTrigger = true;
target.gameObject.AddComponent<score>();


                           
score increases from -2 to -1 ; effect being played on collision.

On the other hand, when the chilli collides with the the bun a you will lose a point and a dark blinding effect will be played out.

if (target.tag == "poisonedfood")
{GUIMenu.score -= 1;
                  ......
                  ...... 
                  ......





score decreases form -2 to -3; a dark blinding effect is being played


In addition, I also added a slow effect to the character, so when the "f" key is pressed, the time will be slowed by half. the turning point is that you will lose 2 points. The "g" will return the time to normal. 2 effects will also be played out, 1 on initiation and the other throughout the effect. For the first effect, I instantiate the effect if the kep is pressed. For the second effect I applied it to the player and set the rate to 0 and the loop to disabled. So when the f key is pressed, It switches on the loop and sets the rate os the particle to a number.


    if (Input.GetKeyDown ("f")) {

GameObject slowfxs = Instantiate(slowfx, this.transform.position,Quaternion.identity) as GameObject;
slowfxs.transform.parent = transform;
            Time.timeScale = 0.4f;
GUIMenu.score -= 2;
this.particleSystem.emissionRate =40;
this.particleSystem.loop =enabled;




Time is being slowed by half and 2 effects are being played out


for the character, its a free model which I downloaded. Then I parented the camera and the burger box as well as the the bun.


Camera and bun are parented under the character.

In addition I also did the move script. Hence the character is able to move right left, up and down aas well as look left and right. The character is able to jump as well.

#region WeMove
//this gets the left and right keys
float move = Input.GetAxis("Horizontal")*Time.deltaTime *speed;
transform.Translate(Vector3.right * move);
float movefront = Input.GetAxis("Vertical")*Time.deltaTime*speed;
transform.Translate(Vector3.forward * movefront);
#endregion
//get the left/right key
float turnrightleft = Input.GetAxis("Mouse X")*Time.deltaTime *rotSpeed;

//this will add the turn to the rotation in y
Vector3 rot = new Vector3(0,transform.localEulerAngles.y + turnrightleft,0);

//update the rotation each frame
transform.localEulerAngles = rot;
if (Input.GetKeyUp("space"))
{
rigidbody.AddRelativeForce(transform.up * jumpPower, ForceMode.Impulse);

Finally I added box colliders to the scene to finalise it.


Box colliders are added to the scene too.








No comments:

Post a Comment