Warning: Undefined array key "url" in /home3/qqksjybd/public_html/wp-content/plugins/wpforms-lite/src/Forms/IconChoices.php on line 127

Warning: Undefined array key "path" in /home3/qqksjybd/public_html/wp-content/plugins/wpforms-lite/src/Forms/IconChoices.php on line 128

Warning: Cannot modify header information - headers already sent by (output started at /home3/qqksjybd/public_html/wp-content/plugins/wpforms-lite/src/Forms/IconChoices.php:127) in /home3/qqksjybd/public_html/wp-includes/feed-rss2.php on line 8
Unity 2D – DIGIDIMENSION https://digidimension.ir Mon, 16 Jan 2023 08:11:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://digidimension.ir/wp-content/uploads/2022/12/icon1.png Unity 2D – DIGIDIMENSION https://digidimension.ir 32 32 Reaction speed test https://digidimension.ir/reaction-speed-test/ https://digidimension.ir/reaction-speed-test/#respond Sat, 24 Dec 2022 18:29:15 +0000 https://digidimension.ir/?p=1416 Here’s how to build a reaction speed test game with Unity.
Hold and release the button until the indicator is between two numbers.

Sample pictures

C# code

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Controller : MonoBehaviour
{
    public float speed = 50;
    public int trueRange = 50;
    public Text minT, maxT, currentText, winORloseText,levelText;
    public Image againPanel , nextPanel , endPanel, levelPanelBack;

    Vector3 rotationPoint = Vector3.zero;
    float temp;
    int maxWinD;
    int minWinD;
    bool hold;
    int Lnum = 1;

    
    // Start is called before the first frame update
    void Start()
    {
        Lnum = PlayerPrefs.GetInt("Level num", 1);
        
        trueRange -= (Lnum - 1) * 10;
        speed *= 1+((float)(Lnum-1)/2);
        //speed *= Lnum;
        levelText.text = "speed = " + speed + "    L E V E L " + Lnum + "    range = " + trueRange;
        
        BackColor();
        SetRange();
    }

    // Update is called once per frame
    void Update()
    {
        temp = Mathf.Round(transform.rotation.eulerAngles.z);
        currentText.text = "" + temp;

        if (hold)
        {
            transform.RotateAround(rotationPoint, Vector3.forward, speed * Time.deltaTime);
        }
        
    } 


    void BackColor()
    {
        switch (Lnum)
        {
            case 1:
                levelPanelBack.color = new Color32(0, 255,50,255);
                break;
            case 2:
                levelPanelBack.color = new Color32(0, 255, 228, 255);
                break;
            case 3:
                levelPanelBack.color = new Color32(0, 50, 255, 255);
                break;
            case 4:
                levelPanelBack.color = new Color32(160, 0, 255, 255);
                break;
            case 5:
                levelPanelBack.color = new Color32(255, 0, 130, 255);
                break;
        }
    }
    void SetRange()
    {
        int winD = Random.Range((trueRange / 2), 360 - (trueRange / 2));
        maxWinD = winD + (trueRange / 2);
        minWinD = winD - (trueRange / 2);

        minT.text = "Min = " + minWinD;
        maxT.text = "Max = " + maxWinD;
    }
    void WinCheck()
    {        
        if (temp <= maxWinD && temp >= minWinD)
        {
            winORloseText.text = "WIN";

            if (trueRange > 10)           
                nextPanel.gameObject.SetActive(true);         
            else           
                endPanel.gameObject.SetActive(true);           
        }
        else
        {
            winORloseText.text = "LOSE";
            againPanel.gameObject.SetActive(true);
        }
    }


    public void StartRotate()
    {
        hold = true;
    }
    public void EndRotate()
    {
        hold = false;
        WinCheck();
    }

    public void Next()
    {
        Lnum += 1;
        PlayerPrefs.SetInt("Level num", Lnum);

        SceneManager.LoadScene(0);     
    }
    public void Again()
    {
        SceneManager.LoadScene(0);
    }
    public void GotoLevel1()
    {
        PlayerPrefs.DeleteAll();
        SceneManager.LoadScene(0);
    }
}

Download unitypackage file

]]>
https://digidimension.ir/reaction-speed-test/feed/ 0
WALLS AND WORDS https://digidimension.ir/walls-and-words/ https://digidimension.ir/walls-and-words/#respond Sat, 24 Dec 2022 18:13:56 +0000 https://digidimension.ir/?p=1403 This is a graffiti art game.

In this game, by touching the mobile screen, you move a brush and spray paint and draw graffiti on the wall. During the game, you must be careful not to collide with obstacles.

Sample pictures

]]>
https://digidimension.ir/walls-and-words/feed/ 0
Funny AR app https://digidimension.ir/funny-ar-app/ https://digidimension.ir/funny-ar-app/#respond Sat, 24 Dec 2022 17:52:03 +0000 https://digidimension.ir/?p=1376 This is an Augmented reality (AR) game made using Unity and Vuforia.
Here, by targeting an image, the player sees a 2D fantasy alien attack game and can play with it.

Sample pictures

C# code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    Rigidbody2D playerRig;
    float _speed = 0;
    Animator boyAnimator;
    SpriteRenderer spriteRenderer;
    public float speed = 10;
    public static float playerXpos;

    // Start is called before the first frame update
    void Start()
    {
        playerRig = gameObject.GetComponent<Rigidbody2D>();
        boyAnimator = GetComponentInChildren<Animator>();
        spriteRenderer = GetComponentInChildren<SpriteRenderer>();
    }

    private void Update()
    {
        playerXpos = transform.position.x;
    }

    private void FixedUpdate()
    {
        playerRig.velocity = new Vector2(_speed, playerRig.velocity.y);
    }

    public void RunR()
    {
        _speed = speed;
        boyAnimator.SetFloat("speed", speed);
        spriteRenderer.flipX = true;
    }
    public void RunL()
    {
        _speed = -speed;
        boyAnimator.SetFloat("speed", speed);
        spriteRenderer.flipX = false;
    }
    public void Stop()
    {
        _speed = 0;
        boyAnimator.SetFloat("speed", 0);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Alien : MonoBehaviour
{
    Animator alienAnimator;
    public float speed = 2;
    float i = 0;

    // Start is called before the first frame update
    void Start()
    {
        alienAnimator = GetComponent<Animator>();
    }

    private void Update()
    {
        transform.Translate(new Vector2(i * speed * Time.deltaTime, 0));
    }

    private void OnCollisionStay2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Ground")
        {
            alienAnimator.SetBool("Run", true);
        }
        else if(collision.gameObject.tag == "Destroy")
        {
            Destroy(gameObject);
        }
    }

    public void StartRun()
    {
        i = (Player.playerXpos - transform.position.x) / Mathf.Abs(Player.playerXpos - transform.position.x);
        //Debug.Log(i);
        //transform.rotation = new Quaternion(0, Mathf.Acos(i), 0, 0);
        GetComponent<SpriteRenderer>().flipX = i < 0;
    }

}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InstantiateObjects : MonoBehaviour
{
    public GameObject flyingSaucer;
    public GameObject[] alien;
    int r;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Inst());
    }

    // Update is called once per frame
    void Update()
    {
        r = Random.Range(0, alien.Length);
    }
    IEnumerator Inst()
    {   
        yield return new WaitForSeconds(2f);
        flyingSaucer.SetActive(true);
        yield return new WaitForSeconds(1.5f);

        for(int i =0; i<10; i++)
        {
            Instantiate(alien[r],transform.position,transform.rotation);
            yield return new WaitForSeconds(5f);
        }
        flyingSaucer.SetActive(false);
    }

}
/*==============================================================================
Copyright (c) 2017 PTC Inc. All Rights Reserved.

Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Protected under copyright and other laws.
==============================================================================*/

using UnityEngine;
using Vuforia;

/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
///
/// Changes made to this file could be overwritten when upgrading the Vuforia version.
/// When implementing custom event handler behavior, consider inheriting from this class instead.
/// </summary>
public class MyTrackableEventHandler : MonoBehaviour, ITrackableEventHandler
{
    #region PROTECTED_MEMBER_VARIABLES

    protected TrackableBehaviour mTrackableBehaviour;
    protected TrackableBehaviour.Status m_PreviousStatus;
    protected TrackableBehaviour.Status m_NewStatus;

    #endregion // PROTECTED_MEMBER_VARIABLES

    #region UNITY_MONOBEHAVIOUR_METHODS

    protected virtual void Start()
    {
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
    }

    protected virtual void OnDestroy()
    {
        if (mTrackableBehaviour)
            mTrackableBehaviour.UnregisterTrackableEventHandler(this);
    }

    #endregion // UNITY_MONOBEHAVIOUR_METHODS

    #region PUBLIC_METHODS

    /// <summary>
    ///     Implementation of the ITrackableEventHandler function called when the
    ///     tracking state changes.
    /// </summary>
    public void OnTrackableStateChanged(
        TrackableBehaviour.Status previousStatus,
        TrackableBehaviour.Status newStatus)
    {
        m_PreviousStatus = previousStatus;
        m_NewStatus = newStatus;

        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
            OnTrackingFound();
        }
        else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
                 newStatus == TrackableBehaviour.Status.NO_POSE)
        {
            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
            OnTrackingLost();
        }
        else
        {
            // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND
            // Vuforia is starting, but tracking has not been lost or found yet
            // Call OnTrackingLost() to hide the augmentations
            OnTrackingLost();
        }
    }

    #endregion // PUBLIC_METHODS

    #region PROTECTED_METHODS

    public GameObject obj;
    public Transform pos;
    GameObject _obj;

    protected virtual void OnTrackingFound()
    {
        _obj = Instantiate(obj, pos.position, pos.rotation);
        _obj.transform.parent = gameObject.transform;

        //var rendererComponents = GetComponentsInChildren<Renderer>(true);
        //var colliderComponents = GetComponentsInChildren<Collider>(true);
        //var canvasComponents = GetComponentsInChildren<Canvas>(true);

        //// Enable rendering:
        //foreach (var component in rendererComponents)
        //    component.enabled = true;

        //// Enable colliders:
        //foreach (var component in colliderComponents)
        //    component.enabled = true;

        //// Enable canvas':
        //foreach (var component in canvasComponents)
        //    component.enabled = true;
    }


    protected virtual void OnTrackingLost()
    {
        Destroy(_obj);

        GameObject[] alienObj = GameObject.FindGameObjectsWithTag("alien");
        foreach (GameObject alObj in alienObj)
        {
            Destroy(alObj);
        }

        //var rendererComponents = GetComponentsInChildren<Renderer>(true);
        //var colliderComponents = GetComponentsInChildren<Collider>(true);
        //var canvasComponents = GetComponentsInChildren<Canvas>(true);

        //// Disable rendering:
        //foreach (var component in rendererComponents)
        //    component.enabled = false;

        //// Disable colliders:
        //foreach (var component in colliderComponents)
        //    component.enabled = false;

        //// Disable canvas':
        //foreach (var component in canvasComponents)
        //    component.enabled = false;
    }

    #endregion // PROTECTED_METHODS
}
]]>
https://digidimension.ir/funny-ar-app/feed/ 0
Throw the ball https://digidimension.ir/throw-the-ball/ https://digidimension.ir/throw-the-ball/#respond Thu, 22 Dec 2022 05:55:52 +0000 https://digidimension.ir/?p=1366 Throw the candy ball and give it to the game character.
In this game, 2D physics and physics material are used in Unity.

Sample pictures

C# code

using System.Collections;
using UnityEngine;

public class Ball : MonoBehaviour
{
    public GameObject eatEffect;
    public Animator eatAnim;
    public AudioSource padAudio;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag == "Pad")
        {
            padAudio.Play();
        }
        else if (collision.tag == "Player")
        {
            StartCoroutine(StartEat());
        }
        else if(collision.tag == "Border")
        {
            gameObject.SetActive(false);
        }
    }

    IEnumerator StartEat()
    {
        eatAnim.SetTrigger("eat");
        eatEffect.SetActive(true);

        yield return new WaitForSeconds(.2f);

        gameObject.GetComponent<SpriteRenderer>().enabled = false;

        yield return new WaitForSeconds(1f);

        eatEffect.SetActive(false);
        gameObject.GetComponent<SpriteRenderer>().enabled = true;
        gameObject.SetActive(false);
    }
}
using System;
using UnityEngine;
using UnityEngine.UI;

public class Run : MonoBehaviour
{
    public GameObject ball;
    Vector3 ballStartPos;
    public Text textX;
    public Text textY;

    void Start()
    {
        ballStartPos = ball.transform.position;
    }
    public void PlayBall()
    {
        int x = Convert.ToInt32(textX.text);
        int y = Convert.ToInt32(textY.text);
        ball.GetComponent<Rigidbody2D>().AddForce(new Vector2(x*100 , y*100));
    }

    public void REstart()
    {
        ball.SetActive(true);
        ball.transform.position = ballStartPos + new Vector3(0, 1, 0);
        ball.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
        ball.GetComponent<Rigidbody2D>().angularVelocity = 0;
    }
}
]]>
https://digidimension.ir/throw-the-ball/feed/ 0
Go to the moon https://digidimension.ir/go-to-the-moon/ https://digidimension.ir/go-to-the-moon/#respond Thu, 22 Dec 2022 05:41:01 +0000 https://digidimension.ir/?p=1353 Here is how to build a small space game in Unity.
You must launch the rocket to the moon without hitting space rocks.

Sample pictures

C# code

using UnityEngine;

public class CameraFollow : MonoBehaviour
{

    public Transform target;
    [Range(0, 1)]
    public float smoothSpeed = 0.125f;
    public Vector3 offset;

    void FixedUpdate()
    {
        if (target != null)
        {
            Vector3 desiredPosition = new Vector3(transform.position.x, target.position.y, transform.position.z) + offset;
            Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
            transform.position = smoothedPosition;

            //transform.LookAt(target);
        }
    }

}
using UnityEngine;
using UnityEngine.SceneManagement;

public class RocketRun : MonoBehaviour
{
    private Rigidbody rg;
    [SerializeField]
    private float force, speed;

    private AudioSource rocketAudio;
    public GameObject rocketParticle;
    public GameObject rocketlight;

    public string nextLevel, startLevel;

    public GameObject ExplosionEffect, finishSound;

    string state = "Play";


    private void Awake()
    {
        rg = GetComponent<Rigidbody>();
        rocketAudio = GetComponent<AudioSource>();
    }
    private void Update()
    {
        if (state == "Play")
        {
            MoveLRRocket();
            RocketSoundAndParticel();
        }
        else
        {
            Stop();
        }
    }

    private void FixedUpdate()
    {
        if (state == "Play")
            MoveUpRocket();
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (state == "Play")
        {
            switch (collision.gameObject.tag)
            {
                case "Dead":
                    Debug.Log("Dead");
                    state = "dead";
                    Dead();
                    break;
                case "Finish":
                    Debug.Log("Finish");
                    state = "finish";
                    Instantiate(finishSound);
                    Invoke("RunNextLevel", 3f);
                    break;
            }
        }
    }

    void MoveUpRocket()
    {
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            rg.AddRelativeForce(Vector3.forward * force * Time.fixedDeltaTime);
        }
    }

    void MoveLRRocket()
    {
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            transform.Rotate(-Vector3.up * speed * Time.deltaTime);
        }
        else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            transform.Rotate(Vector3.up * speed * Time.deltaTime);
        }
    }

    void RocketSoundAndParticel()
    {
        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
        {
            rocketAudio.Play();

            rocketParticle.SetActive(true);
            rocketlight.SetActive(true);
        }
        if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
        {
            rocketAudio.Stop();

            rocketParticle.SetActive(false);
            rocketlight.SetActive(false);
        }
    }

    void Stop()
    {
        rocketAudio.Stop();
        rocketParticle.SetActive(false);
        rocketlight.SetActive(false);
    }

    void RunNextLevel()
    {
        SceneManager.LoadScene(nextLevel);
    }

    void Dead()
    {
        Instantiate(ExplosionEffect, transform.position - new Vector3(0, 0, 1), transform.rotation);
        gameObject.GetComponent<MeshRenderer>().enabled = false;
        Invoke("RunStartLevel", 2f);

    }

    void RunStartLevel()
    {
        SceneManager.LoadScene(startLevel);
    }

}
using UnityEngine;

public class RockTranslate : MonoBehaviour
{
    [SerializeField] [Range(0, 10)] float speed;

    // Update is called once per frame
    void Update()
    {
        transform.Translate(new Vector3(1, 0, 0) * speed * Time.deltaTime);

        if (transform.position.x < -9 || transform.position.x > 9)
            speed = -speed;

    }
}
using UnityEngine;

public class Rotate : MonoBehaviour
{
    public Vector3 ro;

    void Update()
    {
        transform.Rotate(ro * Time.deltaTime);
    }
}
]]>
https://digidimension.ir/go-to-the-moon/feed/ 0
Drag and drop cupcakes https://digidimension.ir/drag-and-drop-cupcakes/ https://digidimension.ir/drag-and-drop-cupcakes/#respond Thu, 22 Dec 2022 05:18:27 +0000 https://digidimension.ir/?p=1339 Here we show the creation of animations from sprites and the use of particle effects and sound effects.
Also shown is a way to drag and drop game objects in Unity.

Sample pictures

C# code

using System.Collections;
using UnityEngine;

public class EatCupcake : MonoBehaviour
{
    public GameObject eatEffect;
    public Animator eatAnim;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Cupcake")
        {
            StartCoroutine(StartEat(collision));
        }
    }

    IEnumerator StartEat(Collider2D collision)
    {
        eatAnim.SetTrigger("eat");
        collision.gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
        collision.gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.zero;

        yield return new WaitForSeconds(.6f);

        eatEffect.SetActive(true);

        yield return new WaitForSeconds(.1f);

        Destroy(collision.gameObject);

        yield return new WaitForSeconds(1f);

        eatEffect.SetActive(false);

    }
}
using UnityEngine;

public class Drog_Drop_mouse : MonoBehaviour
{

    // Update is called once per frame
    void Update()
    {

        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);


        if (Input.GetKey(KeyCode.Mouse0) && (GetComponent<Collider2D>() == Physics2D.OverlapPoint(mousePos)))
        {

            transform.position = new Vector2(mousePos.x, mousePos.y);

        }

    }

}
]]>
https://digidimension.ir/drag-and-drop-cupcakes/feed/ 0
Alien Runner https://digidimension.ir/alien-runner/ https://digidimension.ir/alien-runner/#respond Tue, 20 Dec 2022 13:48:02 +0000 https://digidimension.ir/?p=1298 This is a two-dimensional game called Alien Runner made with Unity.

Sample pictures

]]>
https://digidimension.ir/alien-runner/feed/ 0
2D boy animation https://digidimension.ir/2d-boy-animation/ https://digidimension.ir/2d-boy-animation/#respond Mon, 19 Dec 2022 14:17:44 +0000 https://digidimension.ir/?p=1269 This video is about one of the ways to create two-dimensional animation in Unity, which does not use any assets.

Sample pictures

C# code

using UnityEngine;

public class player : MonoBehaviour {

	private Animator anim;

	// Use this for initialization
	void Start ()
	{
		anim = GetComponent<Animator> ();
	}
	
	// Update is called once per frame
	void Update () 
	{
		
		if (Input.GetMouseButtonDown(0))
		{
			Idle();
		}
		if (Input.GetMouseButtonDown(1))
		{
			Bend();
		}
		if (Input.GetMouseButtonDown(2))
		{
			Walk();
		}
	}

	public void Idle()
    {
		anim.SetBool("bend", false);
		anim.SetBool("walk", false);
	}
	public void Bend()
	{
		anim.SetBool("bend", true);
		anim.SetBool("walk", false);
	}
	public void Walk()
	{
		anim.SetBool("bend", false);
		anim.SetBool("walk", true);
	}
}
]]>
https://digidimension.ir/2d-boy-animation/feed/ 0
Simple Maze https://digidimension.ir/simple-maze/ https://digidimension.ir/simple-maze/#respond Sat, 17 Dec 2022 21:18:39 +0000 https://digidimension.ir/?p=1228 This is a small maze game, The player must reach the end of the path without hitting the walls.
In this video is some information about the player’s movement and the use of some simple materials, audio and the use of post processing.

Sample pictures

C# code

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

	public float speed;
	float x,y;

	// Update is called once per frame
	void Update () {

		if (Accident.health > 0 && !End.endState)
		{
			x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
			y = Input.GetAxis("Vertical") * speed * Time.deltaTime;

			transform.Translate(x, y, 0);
		}
		else if (Accident.health > 0)
        {
			transform.Translate(-0.5f * Time.deltaTime, 0, 0);
		}

	}
}
using UnityEngine;
using System.Collections;

public class Accident : MonoBehaviour {

	public GameObject redPanel;
	public GameObject losePanel;
	public float redTime = .3f;

	public AudioSource audioSource;
	public AudioClip loseClip;

	public static int health = 3;
	
	void OnCollisionEnter2D (Collision2D col){

		if (col.gameObject.tag == "Wall") {

			StartCoroutine(Red());

			GetComponent<AudioSource>().Play();

			health--;

            if (health <= 0)
            {
				Lose();
            }
		}	
	}

	IEnumerator Red()
	{
		redPanel.SetActive(true);
		yield return new WaitForSeconds(redTime);
		redPanel.SetActive(false);
	}

	void Lose()
    {
		losePanel.SetActive(true);
		audioSource.clip = loseClip;
		audioSource.Play();
		Destroy(gameObject, 5);
	}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour
{
    public GameObject[] healthUI = new GameObject[3];
 
    // Update is called once per frame
    void Update()
    {
        switch (Accident.health)
        {
            case 2:
                healthUI[2].SetActive(false);
                break;
            case 1:
                healthUI[1].SetActive(false);
                break;
            case 0:
                healthUI[0].SetActive(false);
                break;
        }
    }
}
using UnityEngine;
using System.Collections;

public class End : MonoBehaviour {

	public GameObject winPanel;
	public AudioSource audioSource;
	public AudioClip winClip;

	public static bool endState;

	void OnTriggerEnter2D (Collider2D col){

		if (col.gameObject.tag == "Player") {

			winPanel.SetActive(true);

			audioSource.clip = winClip;
			audioSource.Play();

			endState = true;
			Destroy(col.gameObject, 5);
		}
	}

}

Simple Maze unitypackage file

]]>
https://digidimension.ir/simple-maze/feed/ 0
Happy Sheep https://digidimension.ir/happy-sheep/ https://digidimension.ir/happy-sheep/#respond Sat, 17 Dec 2022 14:56:56 +0000 https://digidimension.ir/?p=1197 This is a very small game to teach movement, jump and double jump.
Also, the character returns to a specific point, after hitting an obstacle.

Sample pictures

C# code

using UnityEngine;

public class CameraFollow : MonoBehaviour {

	public Transform target;

	public float smoothSpeed = 0.125f;
	public Vector3 offset;

	void FixedUpdate ()
	{
		Vector3 desiredPosition = target.position + offset;
		Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
		transform.position = smoothedPosition;
		//transform.LookAt(target);
	}

}
using UnityEngine;
using System.Collections;

public class Sheep_sc : MonoBehaviour {

	public float speed;
	public float jump;

	public AudioClip[] jumpAudioClip;
	AudioSource jumpAudio;

	public GameObject groundCheck;
	public float groundCheck_r;
	public LayerMask layerMask;
	bool ground;
	bool dudoubleJump;


	private void Start()
	{
		jumpAudio = gameObject.GetComponent<AudioSource>();
	}

	// Update is called once per frame
	void Update () {

		if (!End.end)
		{

			ground = Physics2D.OverlapCircle(groundCheck.transform.position, groundCheck_r, layerMask);

			if (ground)
			{
				dudoubleJump = false;
			}

			if (Input.GetKeyDown(KeyCode.Space) && ground)
			{
				GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);

				jumpAudio.clip = jumpAudioClip[0];
				jumpAudio.Play();
			}

			if (Input.GetKeyDown(KeyCode.Space) && !ground && !dudoubleJump)
			{
				GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
				dudoubleJump = true;

				jumpAudio.clip = jumpAudioClip[1];
				jumpAudio.Play();
			}

			if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
			{
				GetComponent<Rigidbody2D>().velocity = new Vector2(speed, GetComponent<Rigidbody2D>().velocity.y);
				gameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
			}

			if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
			{
				GetComponent<Rigidbody2D>().velocity = new Vector2(-speed, GetComponent<Rigidbody2D>().velocity.y);
				gameObject.transform.rotation = new Quaternion(0, 180, 0, 0);
			}

		}

	}

}
using UnityEngine;
using System.Collections;

public class kill_s : MonoBehaviour {

	public GameObject player;
	public GameObject checkPoint;
	

	void OnTriggerEnter2D(Collider2D col){

		if (col.tag == "Player") {

			gameObject.GetComponent<AudioSource>().Play();
			player.transform.position = checkPoint.transform.position;

		}
	}

}
using UnityEngine;

public class End : MonoBehaviour
{
	public GameObject winPanel;
	public AudioClip winAudioClip;
	public AudioSource winAudio;

	public static bool end = false;
	void OnTriggerEnter2D(Collider2D col)
	{

		if (col.tag == "Player")
		{
			end = true;

			winAudio.clip = winAudioClip;
			winAudio.Play();
			winAudio.loop = false;

			Destroy(gameObject);
			winPanel.SetActive(true);
		}
	}
}

Happy Sheep unitypackage file

]]>
https://digidimension.ir/happy-sheep/feed/ 0