Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by Scribe · Apr 02, 2011 at 09:16 PM · guirotateanglecontrollercolliderhit

Rotating a GUI Texture depending on a Collision

Hello everyone,

I have made a GUI texture for a semi circle with an arrow at the top of the semi circle.

I have made it able to be rotated arund a point using this code:

var Targeter : Texture2D; var Gdepth : int = 0; var rotAngle : float = 0; private var pivotPoint : Vector2; var Scaler = 0.00; var alpha = 1.00;

function OnGUI() { GUI.color = new Color(1,1,1, alpha); GUI.depth = Gdepth; pivotPoint = Vector2(Screen.width/2,Screen.height/2); GUIUtility.RotateAroundPivot (rotAngle, pivotPoint); GUI.DrawTexture(new Rect ((Screen.width/2)-(50*Scaler), (Screen.height/2)-(62*Scaler), (50*Scaler)*2, (50*Scaler)), Targeter, ScaleMode.ScaleToFit);

rotAngle ++; }

however instead of just rotating I want to be able to make the rotation of it equal to a value that is dependent on the point of collision of a bullet with my character collider

For example if the bullet collider that hit me hit my collider at the front the GUI would have a rotation of 0

if I was hit from the left, rotAngle = 270

if I was hit from the right, rotAngle = 90

if I was hit from behind, rotAngle = 180

I am guessing I would use something like ContactPoint, Collision.contacts or ControllerColliderHit.point

but I'm not sure on the best way forward

any help would be much appreciated

Thanks Scribe

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Scribe · May 17, 2011 at 12:27 PM

the whole script I ended up with:

var Targeter : Texture2D; var TargeterCube : Transform; var Gdepth : int = 0; private var pivotPoint : Vector2; var Scaler = 1.00; var alpha = 0.00; var rotAngle : float; var smooth = 2.0; var delayT : int;

function Update () { rotAngle = TargeterCube.eulerAngles.y;

 if(delayT == 0){
 CancelInvoke();
 alpha = 0.0;
 }

}

function OnCollisionEnter () { alpha = 1.0; delayT = 2; InvokeRepeating("Minus1", 1, 1); }

function OnGUI() {

 GUI.color = new Color(1,1,1, alpha);
 GUI.depth = Gdepth;
 pivotPoint = Vector2(Screen.width/2,Screen.height/2);
 GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);

GUI.DrawTexture(new Rect ((Screen.width/2)-(50*Scaler), (Screen.height/2)-(62*Scaler), (50*Scaler)*2, (50*Scaler)), Targeter, ScaleMode.ScaleToFit); }

function Minus1 () { delayT -= 1; }

and the part that actually does the rotating:

GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);

hope that might help someone looking for the same answer as I was

Scribe

Comment
Add comment · Share
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

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

No one has followed this question yet.

Related Questions

Weird angle values from GUIUtility.RotateAroundPivot... 1 Answer

GuiText changing color based on what is behind it (if black it is white and etc) make it easy to read. 0 Answers

Set Rotation Angle 1 Answer

NGUI: Duplicate/Rotate? 0 Answers

Rotating Joystick on Touch 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