Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Pig : MonoBehaviour
- {
- private float timer;
- bool twosecond = true;
- void Start()
- {
- }
- void Update()
- {
- timer += Time.deltaTime;
- if (timer < 2)
- {
- GameObject.Find("Pig").GetComponent<Rigidbody2D>().velocity = new Vector2(1, 0);
- }
- else
- {
- GameObject.Find("Pig").GetComponent<Rigidbody2D>().velocity = new Vector2(-1, 0);
- }
- if (timer >= 4)
- {
- Flip();
- timer = 0;
- twosecond = true;
- }
- if (timer >= 2 && twosecond == true)
- {
- Flip();
- twosecond = false;
- }
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- Rigidbody2D val;
- if(collision.gameObject.TryGetComponent<Rigidbody2D>(out val))
- {
- val.AddForce(new Vector3(-10, 10), ForceMode2D.Impulse);
- }
- }
- void Flip()
- {
- Vector3 Scaler = transform.localScale;
- Scaler.x *= -1;
- transform.localScale = Scaler;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement