Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Nails-of-Scream · Oct 11, 2019 at 08:44 AM · cameraspritevector3

8 Dir Sprites (nearer)

These scripts where from some time ago and now I've decided to get help with them. I've made a script for the sprite direction and one for the character.

1

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DirectionalSprite : MonoBehaviour
 {
     public int directionInt;
     public float charRot;
 
     public float playerAngle;
     Vector2 cameraToSprite;
     Transform playCamera;
     Vector3 direction;
     float angle;
     public float monAngle;
 
     public DemonScript demon;
 
     void Awake()
     {
         playCamera = GameObject.FindWithTag("MainCamera").transform;
     }
 
     // Update is called once per frame
     void Update()
     {
         monAngle = transform.rotation.y * 1;
         direction = (playCamera.transform.position - transform.position).normalized;
         playerAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
         playerAngle += charRot;
 
         if (charRot > 180)
         {
             charRot = 0;
         }
 
         if (charRot < 0)
         {
             charRot = 180;
         }
 
 
         if (playerAngle >= 0f && playerAngle < 45f)
         {
             directionInt = 0;
         }
         else if (playerAngle >= 45f && playerAngle < 90f)
         {
             directionInt = 1;
         }
         else if (playerAngle >= 90f && playerAngle < 135f)
         {
             directionInt = 2;
         }
         else if (playerAngle >= 135f && playerAngle < 180f)
         {
             directionInt = 3;
         }
         else if (playerAngle >= -180f && playerAngle < -135f)
         {
             directionInt = 4;
         }
         else if (playerAngle >= -135f && playerAngle < -90f)
         {
             directionInt = 5;
         }
         else if (playerAngle >= -90f && playerAngle < -45f)
         {
             directionInt = 6;
         }
         else if (playerAngle >= -45f && playerAngle < 0f)
         {
             directionInt = 7;
         }
 
         demon.SetDirection(directionInt);
     }
 }

2

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DemonScript : MonoBehaviour
 {
     // Render
     public SpriteRenderer rend;
     public Sprite[] idleSprites;
     public int spriteIndex;
     int indexCount;
 
     void Awake()
     {
 
     }
 
     public void SetDirection(int directionName) {
         switch(directionName){
             case 0:
                 indexCount = 0;
                 rend.flipX = false;
                 break;
             case 1:
                 indexCount = 1;
                 rend.flipX = false;
                 break;
             case 2:
                 indexCount = 2;
                 rend.flipX = false;
                 break;
             case 3:
                 indexCount = 3;
                 rend.flipX = false;
                 break;
             case 4:
                 indexCount = 4;
                 rend.flipX = false;
                 break;
             case 5:
                 indexCount = 3;
                 rend.flipX = true;
                 break;
             case 6:
                 indexCount = 2;
                 rend.flipX = true;
                 break;
             case 7:
                 indexCount = 1;
                 rend.flipX = true;
                 break;
         }
     }
 
     void Update()
     {
 
         spriteIndex =+ indexCount;
         rend.sprite = idleSprites[spriteIndex];
     }
 }


Any idea how I should do now? And what to fix?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

300 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get the world coordinates of the top left position of the camera? 3 Answers

Getting all sprites to render inside of the Perspective camera 1 Answer

Maintaining look at target between two cameras 1 Answer

ScreenCapture.CaptureScreenshotAsTexture() is making a milky white tinted screenshot. 1 Answer

cut out face from sprite using camera 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges